diff --git a/core/src/main/java/se/su/dsv/scipro/activityplan/Activity.java b/core/src/main/java/se/su/dsv/scipro/activityplan/Activity.java index 1f5182ca05..28e834f5ef 100755 --- a/core/src/main/java/se/su/dsv/scipro/activityplan/Activity.java +++ b/core/src/main/java/se/su/dsv/scipro/activityplan/Activity.java @@ -1,140 +1,164 @@ package se.su.dsv.scipro.activityplan; import com.querydsl.core.annotations.QueryInit; -import jakarta.persistence.GenerationType; -import se.su.dsv.scipro.checklist.Checklist; -import se.su.dsv.scipro.file.FileReference; -import se.su.dsv.scipro.system.LazyDeletableDomainObject; +import jakarta.persistence.Basic; +import jakarta.persistence.Table; import jakarta.persistence.Cacheable; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.persistence.GenerationType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToOne; + +import se.su.dsv.scipro.checklist.Checklist; +import se.su.dsv.scipro.file.FileReference; +import se.su.dsv.scipro.system.LazyDeletableDomainObject; + import java.io.Serializable; -import java.util.*; +import java.util.Comparator; +import java.util.Date; +import java.util.Objects; @Entity +@Table(name = "activity") @Cacheable(true) public class Activity extends LazyDeletableDomainObject { - @Id + + public static IActivityPlan builder(){ + return new Builder(); + } + + // + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne(optional=false) - @JoinColumn (name="activityTemplate_id") - @QueryInit("project") - private ActivityPlan activityPlan; + @Basic + @Column(name = "title", nullable=false) + private String title; - @Column(nullable=false) - private Date date; + @Basic + @Column(name = "date", nullable=false) + private Date date; - @Column(nullable=false) - private String title; - - private String description; - - @OneToOne(optional = true, cascade = CascadeType.ALL) - @JoinColumn(name = "file_upload_reference_id") - private FileReference fileUpload; - - @ManyToOne - private Checklist checklist; + @Basic + @Column(name = "description") + private String description; + @Basic + @Column(name = "editable") private boolean editable = true; @Enumerated(EnumType.STRING) + @Column(name = "action") private Action action = Action.NONE; - + // + + // + @ManyToOne(optional = false) + @JoinColumn(name = "activity_plan_id", referencedColumnName = "id") + @QueryInit("project") + private ActivityPlan activityPlan; + + @ManyToOne + @JoinColumn(name = "checklist_id", referencedColumnName = "id") + private Checklist checklist; + + @OneToOne(optional = true, cascade = CascadeType.ALL) + @JoinColumn(name = "upload_file_reference_id", referencedColumnName = "id") + private FileReference fileUpload; + // + + // public Activity() { this.title = ""; this.description = ""; } + // - @Override - public String toString(){ - return "Event: "+ getTitle()+"@"+getDate(); - } - - @Override + // + @Override public Long getId() { return this.id; } - public ActivityPlan getActivityPlan() { - return this.activityPlan; - } - - public Date getDate() { - return this.date; - } - - public String getTitle() { - return this.title; - } - - public String getDescription() { - return this.description; - } - - public FileReference getFileUpload() { - return this.fileUpload; - } - - public Checklist getChecklist() { - return this.checklist; - } - - public boolean isEditable() { - return this.editable; - } - - public Action getAction() { - return this.action; - } - public void setId(Long id) { this.id = id; } - public void setActivityPlan(ActivityPlan activityPlan) { - this.activityPlan = activityPlan; - } - - public void setDate(Date date) { - this.date = date; + public String getTitle() { + return this.title; } public void setTitle(String title) { this.title = title; } + public Date getDate() { + return this.date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getDescription() { + return this.description; + } + public void setDescription(String description) { this.description = description; } - public void setFileUpload(FileReference fileUpload) { - this.fileUpload = fileUpload; - } - - public void setChecklist(Checklist checklist) { - this.checklist = checklist; + public boolean isEditable() { + return this.editable; } public void setEditable(boolean editable) { this.editable = editable; } + public Action getAction() { + return this.action; + } + public void setAction(Action action) { this.action = action; } + public ActivityPlan getActivityPlan() { + return this.activityPlan; + } + + public void setActivityPlan(ActivityPlan activityPlan) { + this.activityPlan = activityPlan; + } + + public Checklist getChecklist() { + return this.checklist; + } + + public void setChecklist(Checklist checklist) { + this.checklist = checklist; + } + + public FileReference getFileUpload() { + return this.fileUpload; + } + + public void setFileUpload(FileReference fileUpload) { + this.fileUpload = fileUpload; + } + // + + // @Override public boolean equals(final Object o) { if (o == this) return true; @@ -144,15 +168,24 @@ public class Activity extends LazyDeletableDomainObject { && Objects.equals(this.getId(), other.getId()); } - protected boolean canEqual(final Object other) { - return other instanceof Activity; + @Override + public int hashCode() { + return Objects.hashCode(getId()); } @Override - public int hashCode() { - return Objects.hashCode(getId()); - } + public String toString(){ + return "Event: "+ getTitle()+"@"+getDate(); + } + // + // + protected boolean canEqual(final Object other) { + return other instanceof Activity; + } + // + + // public static class ByDateComparator implements Comparator, Serializable { @Override public int compare(Activity o1, Activity o2) { @@ -209,10 +242,6 @@ public class Activity extends LazyDeletableDomainObject { } } - public static IActivityPlan builder(){ - return new Builder(); - } - public interface IActivityPlan { IDate activityPlan(ActivityPlan activityPlan); } @@ -233,4 +262,5 @@ public class Activity extends LazyDeletableDomainObject { IBuild editable(boolean editable); Activity build(); } + // } diff --git a/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityPlan.java b/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityPlan.java index 2ff8883bea..8af7cd3374 100755 --- a/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityPlan.java +++ b/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityPlan.java @@ -1,67 +1,92 @@ package se.su.dsv.scipro.activityplan; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; + +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; -import jakarta.persistence.*; import java.util.Date; import java.util.Objects; import java.util.Set; import java.util.TreeSet; @Entity +@Table(name ="activity_plan") @Cacheable(true) public class ActivityPlan extends DomainObject { + + public static IProject builder() { + return new Builder(); + } + + // @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - + + @Basic + @Column(name = "start_date") + private Date startDate; + // + + // + @OneToOne(optional=false) + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + // + + // @OneToMany(mappedBy= "activityPlan",cascade=CascadeType.PERSIST, orphanRemoval = true) private Set activities = new TreeSet<>(new Activity.ByDateComparator()); - - @OneToOne(optional=false) - private Project project; - - private Date startDate; + // + // @Override public Long getId() { return this.id; } - public Set getActivities() { - return this.activities; - } - - public Project getProject() { - return this.project; - } - - public Date getStartDate() { - return this.startDate; - } - public void setId(Long id) { this.id = id; } - public void setActivities(Set activities) { - this.activities = activities; - } - - public void setProject(Project project) { - this.project = project; + public Date getStartDate() { + return this.startDate; } public void setStartDate(Date startDate) { this.startDate = startDate; } - @Override - public String toString() { - return "ActivityPlan(id=" + this.getId() + ", activities=" + this.getActivities() + ", project=" + this.getProject() + ", startDate=" + this.getStartDate() + ")"; + public Project getProject() { + return this.project; } + public void setProject(Project project) { + this.project = project; + } + + public Set getActivities() { + return this.activities; + } + + public void setActivities(Set activities) { + this.activities = activities; + } + // + + // @Override public boolean equals(final Object o) { if (o == this) return true; @@ -74,15 +99,25 @@ public class ActivityPlan extends DomainObject { && Objects.equals(this.getStartDate(), other.getStartDate()); } - protected boolean canEqual(final Object other) { - return other instanceof ActivityPlan; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getActivities(), this.getProject(), this.getStartDate()); } + @Override + public String toString() { + return "ActivityPlan(id=" + this.getId() + ", activities=" + this.getActivities() + ", project=" + + this.getProject() + ", startDate=" + this.getStartDate() + ")"; + } + // + + // + protected boolean canEqual(final Object other) { + return other instanceof ActivityPlan; + } + // + + // } diff --git a/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityPlanTemplate.java b/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityPlanTemplate.java index 650393135d..b91217a705 100755 --- a/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityPlanTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityPlanTemplate.java @@ -1,98 +1,117 @@ package se.su.dsv.scipro.activityplan; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderColumn; + +import jakarta.persistence.Table; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; -import java.util.*; - @Entity +@Table(name = "activity_plan_template") @Cacheable(true) public class ActivityPlanTemplate extends DomainObject { + // @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OrderColumn(name = "numberInOrder") - @OneToMany(mappedBy="activityPlanTemplate", orphanRemoval=true, cascade=CascadeType.ALL) - private List activityTemplates = new ArrayList<>(); - - public List getActivityTemplates(){ - return Collections.unmodifiableList(activityTemplates); - } - - public void setActivityTemplates(List activityTemplates){ - this.activityTemplates = new ArrayList<>(activityTemplates); - } - - @ManyToOne(optional=false) - private User creator; - - @Column(nullable=false) - private String title; - - @Lob - private String description; - - @Column(nullable=false) + @Basic + @Column(name = "is_sys_admin_template", nullable=false) private boolean isSysAdminTemplate = false; - public void addActivity(ActivityTemplate activity){ - activity.setActivityPlanTemplate(this); - activity.setNumberInOrder(activityTemplates.size()); - activityTemplates.add(activity); - } + @Basic + @Column(name = "title", nullable = false) + private String title; - public void clearActivities(){ - activityTemplates.clear(); - } + @Basic + @Column(name = "description") + @Lob + private String description; + // - public void addActivities(final Collection activities){ - activityTemplates.addAll(activities); - } + // + @ManyToOne(optional = false) + @JoinColumn(name = "creator_user_id", referencedColumnName = "id") + private User creator; + // - @Override + // + @OneToMany(mappedBy="activityPlanTemplate", orphanRemoval=true, cascade=CascadeType.ALL) + @OrderColumn(name = "number_in_order") + private List activityTemplates = new ArrayList<>(); + // + + // + @Override public Long getId() { return this.id; } - public User getCreator() { - return this.creator; - } - - public String getTitle() { - return this.title; - } - - public String getDescription() { - return this.description; - } - - public boolean isSysAdminTemplate() { - return this.isSysAdminTemplate; - } - public void setId(Long id) { this.id = id; } - public void setCreator(User creator) { - this.creator = creator; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setDescription(String description) { - this.description = description; + public boolean isSysAdminTemplate() { + return this.isSysAdminTemplate; } public void setSysAdminTemplate(boolean isSysAdminTemplate) { this.isSysAdminTemplate = isSysAdminTemplate; } + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public User getCreator() { + return this.creator; + } + + public void setCreator(User creator) { + this.creator = creator; + } + + public List getActivityTemplates(){ + return Collections.unmodifiableList(activityTemplates); + } + + public void setActivityTemplates(List activityTemplates){ + this.activityTemplates = new ArrayList<>(activityTemplates); + } + // + + // @Override public boolean equals(final Object o) { if (o == this) return true; @@ -119,6 +138,25 @@ public class ActivityPlanTemplate extends DomainObject { @Override public String toString() { - return "ActivityPlanTemplate(id=" + this.getId() + ", creator=" + this.getCreator() + ", title=" + this.getTitle() + ", description=" + this.getDescription() + ", isSysAdminTemplate=" + this.isSysAdminTemplate() + ")"; + return "ActivityPlanTemplate(id=" + this.getId() + ", creator=" + this.getCreator() + + ", title=" + this.getTitle() + ", description=" + this.getDescription() + + ", isSysAdminTemplate=" + this.isSysAdminTemplate() + ")"; } + // + + // + public void addActivity(ActivityTemplate activity){ + activity.setActivityPlanTemplate(this); + activity.setNumberInOrder(activityTemplates.size()); + activityTemplates.add(activity); + } + + public void clearActivities(){ + activityTemplates.clear(); + } + + public void addActivities(final Collection activities){ + activityTemplates.addAll(activities); + } + // } diff --git a/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityTemplate.java b/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityTemplate.java index c43c8a237c..6671bea897 100755 --- a/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/activityplan/ActivityTemplate.java @@ -1,116 +1,142 @@ package se.su.dsv.scipro.activityplan; +import java.util.Objects; + +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import se.su.dsv.scipro.checklist.ChecklistTemplate; import se.su.dsv.scipro.system.DomainObject; -import jakarta.persistence.*; -import java.util.Objects; - @Entity +@Table(name = "activity_template") public class ActivityTemplate extends DomainObject { + // @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false) + @Basic + @Column(name = "title", nullable = false) private String title; + @Basic + @Column(name = "description") @Lob private String description; - @ManyToOne - private ActivityPlanTemplate activityPlanTemplate; - - @Column(nullable = false) + @Basic + @Column(name = "days_offset", nullable = false) private int daysOffset; + @Basic + @Column(name = "action") @Enumerated(EnumType.STRING) private Action action = Action.NONE; - @Column(nullable = false) + @Basic + @Column(name = "number_in_order", nullable = false) private int numberInOrder = Integer.MAX_VALUE; + // + + // + @ManyToOne + @JoinColumn(name = "activity_plan_template_id", referencedColumnName = "id") + private ActivityPlanTemplate activityPlanTemplate; @ManyToOne(optional = true) + @JoinColumn(name = "checklist_template_id", referencedColumnName = "id") private ChecklistTemplate checklistTemplate; + // + // public ActivityTemplate() { } public ActivityTemplate(int daysOffset) { this.daysOffset = daysOffset; } + // - public int getDaysOffset() { - return daysOffset; - } - - public int getNumberInOrder() { - return numberInOrder; - } - + // @Override public Long getId() { return this.id; } - public String getTitle() { - return this.title; - } - - public String getDescription() { - return this.description; - } - - public ActivityPlanTemplate getActivityPlanTemplate() { - return this.activityPlanTemplate; - } - - public Action getAction() { - return this.action; - } - - public ChecklistTemplate getChecklistTemplate() { - return this.checklistTemplate; - } - public void setId(Long id) { this.id = id; } + public String getTitle() { + return this.title; + } + public void setTitle(String title) { this.title = title; } + public String getDescription() { + return this.description; + } + public void setDescription(String description) { this.description = description; } - public void setActivityPlanTemplate(ActivityPlanTemplate activityPlanTemplate) { - this.activityPlanTemplate = activityPlanTemplate; + public int getDaysOffset() { + return daysOffset; } public void setDaysOffset(int daysOffset) { this.daysOffset = daysOffset; } + public Action getAction() { + return this.action; + } + public void setAction(Action action) { this.action = action; } + public int getNumberInOrder() { + return numberInOrder; + } + public void setNumberInOrder(int numberInOrder) { this.numberInOrder = numberInOrder; } + public ActivityPlanTemplate getActivityPlanTemplate() { + return this.activityPlanTemplate; + } + + public void setActivityPlanTemplate(ActivityPlanTemplate activityPlanTemplate) { + this.activityPlanTemplate = activityPlanTemplate; + } + + public ChecklistTemplate getChecklistTemplate() { + return this.checklistTemplate; + } + public void setChecklistTemplate(ChecklistTemplate checklistTemplate) { this.checklistTemplate = checklistTemplate; } + // - @Override - public String toString() { - return "ActivityTemplate(id=" + this.getId() + ", title=" + this.getTitle() + ", description=" + this.getDescription() + ", activityPlanTemplate=" + this.getActivityPlanTemplate() + ", daysOffset=" + this.getDaysOffset() + ", action=" + this.getAction() + ", numberInOrder=" + this.getNumberInOrder() + ", checklistTemplate=" + this.getChecklistTemplate() + ")"; - } - + // @Override public boolean equals(final Object o) { if (o == this) return true; @@ -120,12 +146,24 @@ public class ActivityTemplate extends DomainObject { && Objects.equals(this.getId(), other.getId()); } - protected boolean canEqual(final Object other) { - return other instanceof ActivityTemplate; - } - @Override public int hashCode() { return Objects.hashCode(this.getId()); } -} \ No newline at end of file + + @Override + public String toString() { + return "ActivityTemplate(id=" + this.getId() + ", title=" + this.getTitle() + + ", description=" + this.getDescription() + ", activityPlanTemplate=" + + this.getActivityPlanTemplate() + ", daysOffset=" + this.getDaysOffset() + ", action=" + + this.getAction() + ", numberInOrder=" + this.getNumberInOrder() + ", checklistTemplate=" + + this.getChecklistTemplate() + ")"; + } + // + + // + protected boolean canEqual(final Object other) { + return other instanceof ActivityTemplate; + } + // +} diff --git a/core/src/main/java/se/su/dsv/scipro/checklist/Checklist.java b/core/src/main/java/se/su/dsv/scipro/checklist/Checklist.java index 3d25b8b1c1..d4c7044f52 100755 --- a/core/src/main/java/se/su/dsv/scipro/checklist/Checklist.java +++ b/core/src/main/java/se/su/dsv/scipro/checklist/Checklist.java @@ -1,12 +1,33 @@ package se.su.dsv.scipro.checklist; - +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapKeyJoinColumn; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; @Entity @Table(name = "checklist") @@ -17,6 +38,7 @@ public class Checklist extends DomainObject { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic @Column(nullable = false) private String name; @@ -28,15 +50,26 @@ public class Checklist extends DomainObject { */ @Deprecated @ManyToOne(optional = false) + @JoinColumn(name = "project_id") private Project project; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinTable(name = "checklist_checklist_question", + joinColumns = @JoinColumn(name = "checklist_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "checklist_question_id", referencedColumnName = "id")) private List questions = new ArrayList<>(); @ManyToMany + @JoinTable(name = "checklist_checklist_category", + joinColumns = @JoinColumn(name = "checklist_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "checklist_category_id", referencedColumnName = "id")) private List categories = new ArrayList<>(); @ElementCollection(fetch = FetchType.EAGER) + @CollectionTable(name = "checklist_user_last_open_date", joinColumns = @JoinColumn(name = "checklist_id")) + @Column(name = "last_open_date") + @SuppressWarnings("JpaDataSourceORMInspection") // false warning from IntelliJ for the @MapKeyJoinColumn + @MapKeyJoinColumn(name = "user_id") private Map userLastOpenDate = new HashMap<>(); protected Checklist() { diff --git a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistAnswer.java b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistAnswer.java index 05d756e6a1..704f907f40 100755 --- a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistAnswer.java +++ b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistAnswer.java @@ -1,29 +1,54 @@ package se.su.dsv.scipro.checklist; +import java.util.Objects; + +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; -import java.util.Objects; - @Entity @Table(name = "checklist_answer") public class ChecklistAnswer extends DomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic + @Column(name = "answer", nullable = false) @Enumerated(EnumType.STRING) - @Column(nullable = false) private ChecklistAnswerEnum answer; - @ManyToOne(optional = false) - private User user; - + @Basic + @Column(name = "comment") @Lob - @Column private String comment; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (checklist_answer) referencing other + // tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + @JoinColumn(name = "user_id", referencedColumnName = "id") + private User user; + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected ChecklistAnswer() { } @@ -36,44 +61,45 @@ public class ChecklistAnswer extends DomainObject { this.answer = answer != null ? answer : ChecklistAnswerEnum.NO_ANSWER; } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public ChecklistAnswerEnum getAnswer() { - return this.answer; - } - - public User getUser() { - return this.user; - } - - public String getComment() { - return this.comment; - } - public void setId(Long id) { this.id = id; } + public ChecklistAnswerEnum getAnswer() { + return this.answer; + } + public void setAnswer(ChecklistAnswerEnum answer) { this.answer = answer; } - public void setUser(User user) { - this.user = user; + public String getComment() { + return this.comment; } public void setComment(String comment) { this.comment = comment; } - @Override - public String toString() { - return "ChecklistAnswer(id=" + this.getId() + ", answer=" + this.getAnswer() + ", user=" + this.getUser() + ", comment=" + this.getComment() + ")"; + public User getUser() { + return this.user; } + public void setUser(User user) { + this.user = user; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -83,12 +109,21 @@ public class ChecklistAnswer extends DomainObject { && Objects.equals(this.getId(), other.getId()); } - protected boolean canEqual(final Object other) { - return other instanceof ChecklistAnswer; - } - @Override public int hashCode() { return Objects.hashCode(this.getId()); } + + @Override + public String toString() { + return "ChecklistAnswer(id=" + this.getId() + ", answer=" + this.getAnswer() + ", user=" + this.getUser() + + ", comment=" + this.getComment() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof ChecklistAnswer; + } } \ No newline at end of file diff --git a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistAnswerEnum.java b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistAnswerEnum.java index 796d0ddeeb..e806794440 100755 --- a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistAnswerEnum.java +++ b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistAnswerEnum.java @@ -4,6 +4,6 @@ public enum ChecklistAnswerEnum { RED, GREEN, YELLOW, - NOT_APLICABLE, + NOT_APPLICABLE, NO_ANSWER } diff --git a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistCategory.java b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistCategory.java index ed0f76c658..c3589be745 100755 --- a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistCategory.java +++ b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistCategory.java @@ -1,13 +1,17 @@ -/** - * - */ package se.su.dsv.scipro.checklist; -import se.su.dsv.scipro.system.DomainObject; - -import jakarta.persistence.*; import java.util.Objects; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import se.su.dsv.scipro.system.DomainObject; + @Entity @Table(name="checklist_category") @Cacheable(true) @@ -16,7 +20,7 @@ public class ChecklistCategory extends DomainObject { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(unique=true) + @Column(name = "category_name", unique = true) private String categoryName; protected ChecklistCategory() { diff --git a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistQuestion.java b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistQuestion.java index 337551dc04..3678024780 100755 --- a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistQuestion.java +++ b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistQuestion.java @@ -1,13 +1,26 @@ package se.su.dsv.scipro.checklist; -import se.su.dsv.scipro.system.DomainObject; -import se.su.dsv.scipro.system.User; - -import jakarta.persistence.*; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.Lob; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; + +import se.su.dsv.scipro.system.DomainObject; +import se.su.dsv.scipro.system.User; + @Entity @Table(name = "checklist_question") @Cacheable(true) @@ -20,13 +33,15 @@ public class ChecklistQuestion extends DomainObject { @Column(nullable = false) private String question; - @Column(nullable = false) + @Basic + @Column(name = "question_number", nullable = false) private int questionNumber; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinTable( - joinColumns = @JoinColumn(name = "checklist_question_id") - ) + name = "checklist_question_checklist_answer", + joinColumns = @JoinColumn(name = "checklist_question_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "checklist_answer_id", referencedColumnName = "id")) private List answers = new ArrayList<>(); protected ChecklistQuestion() { diff --git a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistTemplate.java b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistTemplate.java index 05b09733b1..12ad047041 100755 --- a/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/checklist/ChecklistTemplate.java @@ -1,11 +1,27 @@ package se.su.dsv.scipro.checklist; +import jakarta.persistence.Basic; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; @Entity @Table(name = "checklist_template") @@ -17,35 +33,42 @@ public class ChecklistTemplate extends DomainObject { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic @Column(nullable = false) private String name; @Basic(optional = true) + @Column(name = "description") private String description; - @Column + @Basic + @Column(name = "template_number") private int templateNumber = DEFAULT_TEMPLATE_NUMBER; - @Lob @ElementCollection + @CollectionTable(name = "checklist_template_question", + joinColumns = @JoinColumn(name = "checklist_template_id")) + @Column(name = "question") private List questions = new ArrayList<>(1); @ManyToOne(optional = false) + @JoinColumn(name = "creator_user_id", referencedColumnName = "id") private User creator; @ManyToMany - @JoinTable( - joinColumns = @JoinColumn(name = "checklist_template_id") - ) + @JoinTable(name = "checklist_template_checklist_category", + joinColumns = @JoinColumn(name = "checklist_template_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "checklist_category_id", referencedColumnName = "id")) private List categories = new ArrayList<>(); @ManyToMany - @JoinTable(name = "checklist_template_ProjectType", + @JoinTable(name = "checklist_template_project_type", joinColumns = {@JoinColumn(name = "checklist_template_id")}, - inverseJoinColumns = {@JoinColumn(name = "projectType_id")}) + inverseJoinColumns = {@JoinColumn(name = "project_type_id")}) private Collection projectTypes = new HashSet<>(); public ChecklistTemplate() { + } public ChecklistTemplate(String name, User creator) { diff --git a/core/src/main/java/se/su/dsv/scipro/file/FileDescription.java b/core/src/main/java/se/su/dsv/scipro/file/FileDescription.java index 7b4060922b..ac42cab487 100755 --- a/core/src/main/java/se/su/dsv/scipro/file/FileDescription.java +++ b/core/src/main/java/se/su/dsv/scipro/file/FileDescription.java @@ -33,25 +33,40 @@ public class FileDescription extends DomainObject { public static final int FILES_PER_SUBDIRECTORY = 1000; public static final String FILE_ROOT = "/scipro-files"; + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column + @Basic + @Column(name = "name") private String name; - @Column + @Basic + @Column(name = "mime_type") private String mimeType; - @Column - private String identifier; - - @ManyToOne - @JoinColumn(name = "userId") - private User uploader; - + @Basic + @Column(name = "size") private long size; + @Basic + @Column(name = "file_identifier") + private String identifier; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (file_description) referencing + // other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne + @JoinColumn(name = "user_id", referencedColumnName = "id") + private User uploader; + + // ---------------------------------------------------------------------------------- + // JPA lifecycle methods + // ---------------------------------------------------------------------------------- @PostRemove void removeActualData() { try { @@ -63,6 +78,96 @@ public class FileDescription extends DomainObject { } } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMimeType() { + return this.mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public long getSize() { + return this.size; + } + + public void setSize(long size) { + this.size = size; + } + + public String getIdentifier() { + return this.identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public User getUploader() { + return this.uploader; + } + + public void setUploader(User uploader) { + this.uploader = uploader; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof FileDescription)) return false; + final FileDescription other = (FileDescription) o; + return other.canEqual(this) + && Objects.equals(this.getId(), other.getId()); + } + + @Override + public int hashCode() { + final int PRIME = 59; + int result = 1; + final Object $id = this.getId(); + result = result * PRIME + ($id == null ? 43 : $id.hashCode()); + return result; + } + + // Todo + @Override + public String toString() { + if (name != null) { + return name; + } else { + return super.toString(); + } + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof FileDescription; + } + public Path getPath0() { return FileSystems.getDefault().getPath(FILE_ROOT, getSubdirectory(), Long.toString(id)); } @@ -78,85 +183,4 @@ public class FileDescription extends DomainObject { public InputStream getData() throws IOException { return Files.newInputStream(getPath0()); } - - public String getName() { - return name; - } - - // Todo - @Override - public String toString() { - if (name != null) { - return name; - } else { - return super.toString(); - } - } - - @Override - public Long getId() { - return this.id; - } - - public String getMimeType() { - return this.mimeType; - } - - public String getIdentifier() { - return this.identifier; - } - - public User getUploader() { - return this.uploader; - } - - public long getSize() { - return this.size; - } - - public void setId(Long id) { - this.id = id; - } - - public void setName(String name) { - this.name = name; - } - - public void setMimeType(String mimeType) { - this.mimeType = mimeType; - } - - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - public void setUploader(User uploader) { - this.uploader = uploader; - } - - public void setSize(long size) { - this.size = size; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof FileDescription)) return false; - final FileDescription other = (FileDescription) o; - return other.canEqual(this) - && Objects.equals(this.getId(), other.getId()); - } - - protected boolean canEqual(final Object other) { - return other instanceof FileDescription; - } - - @Override - public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $id = this.getId(); - result = result * PRIME + ($id == null ? 43 : $id.hashCode()); - return result; - } } diff --git a/core/src/main/java/se/su/dsv/scipro/file/FileReference.java b/core/src/main/java/se/su/dsv/scipro/file/FileReference.java index 34f7ce0beb..4858d090db 100644 --- a/core/src/main/java/se/su/dsv/scipro/file/FileReference.java +++ b/core/src/main/java/se/su/dsv/scipro/file/FileReference.java @@ -9,7 +9,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import java.io.Serializable; -import java.util.*; +import java.util.Objects; /** * A reference to a file. @@ -29,7 +29,7 @@ public class FileReference implements Serializable { private Long id; @ManyToOne(cascade = CascadeType.PERSIST) - @JoinColumn(name = "file_description_id") + @JoinColumn(name = "file_description_id", referencedColumnName = "id") private FileDescription fileDescription; public Long getId() { diff --git a/core/src/main/java/se/su/dsv/scipro/file/ProjectFile.java b/core/src/main/java/se/su/dsv/scipro/file/ProjectFile.java index d63c05d4d0..ba57470626 100644 --- a/core/src/main/java/se/su/dsv/scipro/file/ProjectFile.java +++ b/core/src/main/java/se/su/dsv/scipro/file/ProjectFile.java @@ -1,71 +1,88 @@ package se.su.dsv.scipro.file; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; -import jakarta.persistence.*; import java.util.Objects; @Entity @Table(name = "project_file") public class ProjectFile extends DomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - private Project project; - + @Basic + @Column(name = "file_source") @Enumerated(EnumType.STRING) private FileSource fileSource = FileSource.FILES; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (project_file) referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + @OneToOne - @JoinColumn(name = "file_reference_id") + @JoinColumn(name = "file_reference_id", referencedColumnName = "id") private FileReference fileReference; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public Project getProject() { - return this.project; - } - - public FileSource getFileSource() { - return this.fileSource; - } - - public FileDescription getFileDescription() { - return this.fileReference.getFileDescription(); - } - public void setId(Long id) { this.id = id; } - public void setProject(Project project) { - this.project = project; + public FileSource getFileSource() { + return this.fileSource; } public void setFileSource(FileSource fileSource) { this.fileSource = fileSource; } - public void setFileReference(FileReference fileReference) { - this.fileReference = fileReference; - } - public FileReference getFileReference() { return this.fileReference; } - @Override - public String toString() { - return "ProjectFile(id=" + this.getId() + ", project=" + this.getProject() + ", fileSource=" + this.getFileSource() + ", fileDescription=" + this.getFileDescription() + ")"; + public void setFileReference(FileReference fileReference) { + this.fileReference = fileReference; } + public Project getProject() { + return this.project; + } + + public void setProject(Project project) { + this.project = project; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -79,12 +96,24 @@ public class ProjectFile extends DomainObject { && Objects.equals(this.getFileDescription(), other.getFileDescription()); } - protected boolean canEqual(final Object other) { - return other instanceof ProjectFile; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getProject(), this.getFileSource(), this.getFileDescription()); } + + @Override + public String toString() { + return "ProjectFile(id=" + this.getId() + ", project=" + this.getProject() + ", fileSource=" + this.getFileSource() + ", fileDescription=" + this.getFileDescription() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof ProjectFile; + } + + public FileDescription getFileDescription() { + return this.fileReference.getFileDescription(); + } } diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminar.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminar.java index 461be0f88c..1679e993a0 100755 --- a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminar.java +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminar.java @@ -23,7 +23,15 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import jakarta.persistence.Table; -import java.util.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; @Entity @Table(name = "final_seminar") @@ -35,27 +43,69 @@ public class FinalSeminar extends LazyDeletableDomainObject { public static final int DEFAULT_MAX_PARTICIPANTS = 5; public static final String FINAL_SEMINAR = "finalSeminar"; + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(optional = false) - @QueryInit({"projectType", "headSupervisor"}) - private Project project; - @Basic(optional = false) + @Column(name = "start_date") private Date startDate; @Basic(optional = false) + @Column(name = "room") private String room; + @Basic + @Column(name = "max_opponents") + private int maxOpponents = DEFAULT_MAX_OPPONENTS; + + @Basic + @Column(name = "max_participants") + private int maxParticipants = DEFAULT_MAX_PARTICIPANTS; + + @Enumerated(EnumType.STRING) + @Column(name = "presentation_lang") + private Language presentationLanguage; + + @Basic + @Column(name = "document_upload_date") + private Date documentUploadDate; + @Basic @Column(name = "extra_info") private String extraInfo; @Basic + @Column(name = "creation_reason") + private String creationReason; + + @Basic + @Column(name = "manual_participants") private Boolean manualParticipants = false; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (final_seminar) referencing other tables. + // ---------------------------------------------------------------------------------- + /* + * Cascading delete, set document to nul will delete the filedescription but + * not the actual file. Use FinarSeminarUploadController.deleteSeminarReport + * to delete the document + */ + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "document_file_reference_id", referencedColumnName = "id") + private FileReference document; + + @OneToOne(optional = false) + @JoinColumn(name = "project_id", referencedColumnName = "id") + @QueryInit({"projectType", "headSupervisor"}) + private Project project; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "final_seminar" + // ---------------------------------------------------------------------------------- @OneToMany(mappedBy = FINAL_SEMINAR, orphanRemoval = true, cascade = CascadeType.ALL) private Set activeParticipations = new HashSet<>(); @@ -65,28 +115,10 @@ public class FinalSeminar extends LazyDeletableDomainObject { @OneToMany(mappedBy = FINAL_SEMINAR, orphanRemoval = true, cascade = CascadeType.ALL) private Set respondents = new HashSet<>(); - /* - * Cascading delete, set document to nul will delete the filedescription but - * not the actual file. Use FinarSeminarUploadController.deleteSeminarReport - * to delete the document - */ - @OneToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "document_reference_id") - private FileReference document; - - private Date documentUploadDate; - - @Enumerated(EnumType.STRING) - private Language presentationLanguage; - - private int maxOpponents = DEFAULT_MAX_OPPONENTS; - private int maxParticipants = DEFAULT_MAX_PARTICIPANTS; - - @Basic - private String creationReason; - + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- public FinalSeminar() { - } public FinalSeminar(int maxOpponents, int maxParticipants) { @@ -99,6 +131,90 @@ public class FinalSeminar extends LazyDeletableDomainObject { this.project = project; } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public boolean isCancelled() { + return isDeleted(); + } + + public void setCancelled(boolean cancelled) { + setDeleted(cancelled); + } + + public Date getStartDate() { + return this.startDate; + } + + public void setStartDate(Date startDate) { + this.startDate = (Date) startDate.clone(); + } + + public String getRoom() { + return this.room; + } + + public void setRoom(String room) { + this.room = room; + } + + public int getMaxOpponents() { + return this.maxOpponents; + } + + public void setMaxOpponents(int maxOpponents) { + this.maxOpponents = maxOpponents; + } + + public int getMaxParticipants() { + return this.maxParticipants; + } + + public void setMaxParticipants(int maxParticipants) { + this.maxParticipants = maxParticipants; + } + + public Language getPresentationLanguage() { + return this.presentationLanguage; + } + + public void setPresentationLanguage(Language presentationLanguage) { + this.presentationLanguage = presentationLanguage; + } + + public Date getDocumentUploadDate() { + return this.documentUploadDate; + } + + public void setDocumentUploadDate(Date documentUploadDate) { + this.documentUploadDate = documentUploadDate; + } + + public String getExtraInfo() { + return extraInfo; + } + + public void setExtraInfo(String extraInfo) { + this.extraInfo = extraInfo; + } + + public String getCreationReason() { + return this.creationReason; + } + + public void setCreationReason(String creationReason) { + this.creationReason = creationReason; + } + public Boolean getManualParticipants() { return manualParticipants; } @@ -107,21 +223,83 @@ public class FinalSeminar extends LazyDeletableDomainObject { this.manualParticipants = manualParticipants; } - public void setStartDate(Date startDate) { - this.startDate = (Date) startDate.clone(); + public FileReference getDocument() { + return this.document; + } + + public void setDocument(FileReference document) { + this.document = document; } public Project getProject() { return project; } + public void setProject(Project project) { + this.project = project; + } + + public Set getActiveParticipations() { + return Collections.unmodifiableSet(activeParticipations); + } + public void setActiveParticipations(Collection activeParticipations) { this.activeParticipations.clear(); this.activeParticipations.addAll(activeParticipations); } - public Set getActiveParticipations() { - return Collections.unmodifiableSet(activeParticipations); + public Set getOppositions() { + return Collections.unmodifiableSet(oppositions); + } + + public void setOppositions(Collection oppositions) { + this.oppositions.clear(); + this.oppositions.addAll(oppositions); + } + + public Set getRespondents() { + return this.respondents; + } + + public void setRespondents(Set respondents) { + this.respondents = respondents; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof FinalSeminar)) return false; + final FinalSeminar other = (FinalSeminar) o; + return other.canEqual(this) + && super.equals(o) + && Objects.equals(this.getId(), other.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.getId()); + } + + @Override + public String toString() { + return "FinalSeminar(id=" + this.getId() + ", project=" + this.getProject() + ", startDate=" + + this.getStartDate() + ", room=" + this.getRoom() + ", activeParticipations=" + + this.getActiveParticipations() + ", oppositions=" + this.getOppositions() + + ", respondents=" + this.getRespondents() + ", document=" + this.getDocument() + + ", documentUploadDate=" + this.getDocumentUploadDate() + ", presentationLanguage=" + + this.getPresentationLanguage() + ", maxOpponents=" + this.getMaxOpponents() + + ", maxParticipants=" + this.getMaxParticipants() + ", creationReason=" + + this.getCreationReason() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof FinalSeminar; } public void addActiveParticipant(FinalSeminarActiveParticipation participation) { @@ -132,25 +310,62 @@ public class FinalSeminar extends LazyDeletableDomainObject { this.activeParticipations.remove(participation); } - public void setOppositions(Collection oppositions) { - this.oppositions.clear(); - this.oppositions.addAll(oppositions); + public void removeActiveParticipant(User user) { + activeParticipations.removeIf(next -> next.getUser().equals(user)); } - public Set getOppositions() { - return Collections.unmodifiableSet(oppositions); + public Set getActiveParticipants(){ + Set activeParticipants = new HashSet<>(); + for (FinalSeminarActiveParticipation fsap : activeParticipations){ + activeParticipants.add(fsap.getUser()); + } + return activeParticipants; + } + + public Collection getNotGradedActiveParticipations() { + return getNotGradedParticipations(activeParticipations); } public void addOpposition(FinalSeminarOpposition opposition) { this.oppositions.add(opposition); } + public void removeOpposition(FinalSeminarOpposition opposition) { + this.oppositions.remove(opposition); + } + + public Set getOpponents(){ + Set opponents = new HashSet<>(); + for (FinalSeminarOpposition fso : oppositions){ + opponents.add(fso.getUser()); + } + return opponents; + } + + public Collection getNotGradedOpponents() { + return getNotGradedParticipations(oppositions); + } + + public Collection getNotGradedRespondents() { + return getNotGradedParticipations(respondents); + } + + private Collection getNotGradedParticipations(Set participations) { + List result = new ArrayList<>(); + for (FinalSeminarParticipation participation : participations) { + if(participation.getGrade() == null) { + result.add(participation.getUser()); + } + } + return result; + } + public int getMinOpponents() { - return project.getMinOpponentsOnFinalSeminar(); + return getProject().getMinOpponentsOnFinalSeminar(); } public int getMinActiveParticipants() { - return project.getMinFinalSeminarActiveParticipation(); + return getProject().getMinFinalSeminarActiveParticipation(); } public List getMembers() { @@ -172,177 +387,10 @@ public class FinalSeminar extends LazyDeletableDomainObject { } public ProjectType getProjectType() { - return project.getProjectType(); + return getProject().getProjectType(); } public String getProjectTitle() { - return project.getTitle(); + return getProject().getTitle(); } - - public void setCancelled(boolean cancelled) { - setDeleted(cancelled); - } - - public boolean isCancelled() { - return isDeleted(); - } - - public void removeOpposition(FinalSeminarOpposition opposition) { - this.oppositions.remove(opposition); - } - - public Collection getNotGradedOpponents() { - return getNotGradedParticipations(oppositions); - } - - public Collection getNotGradedActiveParticipations() { - return getNotGradedParticipations(activeParticipations); - } - - public Collection getNotGradedRespondents() { - return getNotGradedParticipations(respondents); - } - - private Collection getNotGradedParticipations(Set participations) { - List result = new ArrayList<>(); - for (FinalSeminarParticipation participation : participations) { - if(participation.getGrade() == null) { - result.add(participation.getUser()); - } - } - return result; - } - - public Set getOpponents(){ - Set opponents = new HashSet<>(); - for (FinalSeminarOpposition fso : oppositions){ - opponents.add(fso.getUser()); - } - return opponents; - } - - public Set getActiveParticipants(){ - Set activeParticipants = new HashSet<>(); - for (FinalSeminarActiveParticipation fsap : activeParticipations){ - activeParticipants.add(fsap.getUser()); - } - return activeParticipants; - } - - public void removeActiveParticipant(User user) { - activeParticipations.removeIf(next -> next.getUser().equals(user)); - } - - @Override - public Long getId() { - return this.id; - } - - public Date getStartDate() { - return this.startDate; - } - - public String getRoom() { - return this.room; - } - - public Set getRespondents() { - return this.respondents; - } - - public FileReference getDocument() { - return this.document; - } - - public Date getDocumentUploadDate() { - return this.documentUploadDate; - } - - public Language getPresentationLanguage() { - return this.presentationLanguage; - } - - public int getMaxOpponents() { - return this.maxOpponents; - } - - public int getMaxParticipants() { - return this.maxParticipants; - } - - public void setId(Long id) { - this.id = id; - } - - public void setProject(Project project) { - this.project = project; - } - - public void setRoom(String room) { - this.room = room; - } - - public void setRespondents(Set respondents) { - this.respondents = respondents; - } - - public void setDocument(FileReference document) { - this.document = document; - } - - public void setDocumentUploadDate(Date documentUploadDate) { - this.documentUploadDate = documentUploadDate; - } - - public void setPresentationLanguage(Language presentationLanguage) { - this.presentationLanguage = presentationLanguage; - } - - public void setMaxOpponents(int maxOpponents) { - this.maxOpponents = maxOpponents; - } - - public void setMaxParticipants(int maxParticipants) { - this.maxParticipants = maxParticipants; - } - - public void setCreationReason(String creationReason) { - this.creationReason = creationReason; - } - - public String getExtraInfo() { - return extraInfo; - } - - public void setExtraInfo(String extraInfo) { - this.extraInfo = extraInfo; - } - - @Override - public String toString() { - return "FinalSeminar(id=" + this.getId() + ", project=" + this.getProject() + ", startDate=" + this.getStartDate() + ", room=" + this.getRoom() + ", activeParticipations=" + this.getActiveParticipations() + ", oppositions=" + this.getOppositions() + ", respondents=" + this.getRespondents() + ", document=" + this.getDocument() + ", documentUploadDate=" + this.getDocumentUploadDate() + ", presentationLanguage=" + this.getPresentationLanguage() + ", maxOpponents=" + this.getMaxOpponents() + ", maxParticipants=" + this.getMaxParticipants() + ", creationReason=" + this.getCreationReason() + ")"; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof FinalSeminar)) return false; - final FinalSeminar other = (FinalSeminar) o; - return other.canEqual(this) - && super.equals(o) - && Objects.equals(this.getId(), other.getId()); - } - - protected boolean canEqual(final Object other) { - return other instanceof FinalSeminar; - } - - @Override - public int hashCode() { - return Objects.hashCode(this.getId()); - } - - public String getCreationReason() { - return this.creationReason; - } -} \ No newline at end of file +} diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarActiveParticipation.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarActiveParticipation.java index 4930b37979..fdc7bf1429 100755 --- a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarActiveParticipation.java +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarActiveParticipation.java @@ -1,5 +1,6 @@ package se.su.dsv.scipro.finalseminar; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.project.Project; import jakarta.persistence.Cacheable; @@ -9,13 +10,20 @@ import jakarta.persistence.Table; import java.util.Objects; @Entity -@Cacheable(true) @Table(name = "final_seminar_active_participation") +@Cacheable(true) public class FinalSeminarActiveParticipation extends FinalSeminarParticipation { - + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (final_seminar_active_participation) + // referencing other tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional = false) + @JoinColumn(name = "project_id", referencedColumnName = "id") private Project project; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Project getProject() { return this.project; } @@ -24,6 +32,9 @@ public class FinalSeminarActiveParticipation extends FinalSeminarParticipation { this.project = project; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -34,13 +45,16 @@ public class FinalSeminarActiveParticipation extends FinalSeminarParticipation { && Objects.equals(this.project, other.project); } - @Override - protected boolean canEqual(final Object other) { - return other instanceof FinalSeminarActiveParticipation; - } - @Override public int hashCode() { return Objects.hash(super.hashCode(), this.getProject()); } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + @Override + protected boolean canEqual(final Object other) { + return other instanceof FinalSeminarActiveParticipation; + } } diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOpposition.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOpposition.java index 65cf89e756..de9c6cd3a4 100755 --- a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOpposition.java +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarOpposition.java @@ -13,73 +13,90 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToOne; import jakarta.persistence.Table; -import java.util.*; + +import java.util.Objects; @Entity @Table(name="final_seminar_opposition") public class FinalSeminarOpposition extends FinalSeminarParticipation { - public static final int FEEDBACK_LENGTH = 2000; - @ManyToOne(optional = false) - private Project project; - - @OneToOne - @JoinColumn(name = "opponent_report_reference_id") - private FileReference opponentReport; - - @OneToOne(optional = true, orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "finalSeminarOpposition") - private OppositionReport oppositionReport; + private static final int FEEDBACK_LENGTH = 2000; + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Basic + @Column(name = "points") private Integer points; @Basic - @Column(length = FEEDBACK_LENGTH) + @Column(name = "feedback", length = FEEDBACK_LENGTH) private String feedback; - public ProjectType getProjectType() { - return getFinalSeminar().getProject().getProjectType(); - } + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (final_seminar_opposition) referencing + // other tables. + // ---------------------------------------------------------------------------------- + @OneToOne + @JoinColumn(name = "opponent_report_file_reference_id", referencedColumnName = "id") + private FileReference opponentReport; - public void setProject(final Project project) { - this.project = project; - } + @ManyToOne(optional = false) + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; - public Project getProject() { - return this.project; - } - - public FileReference getOpponentReport() { - return this.opponentReport; - } - - public OppositionReport getOppositionReport() { - return this.oppositionReport; - } + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table (final_seminar_opposition) + // ---------------------------------------------------------------------------------- + @OneToOne(optional = true, orphanRemoval = true, cascade = CascadeType.ALL, + mappedBy = "finalSeminarOpposition") + private OppositionReport oppositionReport; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Integer getPoints() { return this.points; } - public String getFeedback() { - return this.feedback; - } - - public void setOpponentReport(FileReference opponentReport) { - this.opponentReport = opponentReport; - } - - public void setOppositionReport(OppositionReport oppositionReport) { - this.oppositionReport = oppositionReport; - } - public void setPoints(Integer points) { this.points = points; } + public String getFeedback() { + return this.feedback; + } + public void setFeedback(String feedback) { this.feedback = feedback; } + public FileReference getOpponentReport() { + return this.opponentReport; + } + + public void setOpponentReport(FileReference opponentReport) { + this.opponentReport = opponentReport; + } + + public Project getProject() { + return this.project; + } + + public void setProject(final Project project) { + this.project = project; + } + + public OppositionReport getOppositionReport() { + return this.oppositionReport; + } + + public void setOppositionReport(OppositionReport oppositionReport) { + this.oppositionReport = oppositionReport; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -90,13 +107,20 @@ public class FinalSeminarOpposition extends FinalSeminarParticipation { && Objects.equals(this.getProject(), other.getProject()); } + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), this.getProject()); + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- @Override protected boolean canEqual(final Object other) { return other instanceof FinalSeminarOpposition; } - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), this.getProject()); + public ProjectType getProjectType() { + return getFinalSeminar().getProject().getProjectType(); } } diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarParticipation.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarParticipation.java index 43d94e05e8..8d97c21020 100644 --- a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarParticipation.java +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarParticipation.java @@ -1,64 +1,66 @@ package se.su.dsv.scipro.finalseminar; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MappedSuperclass; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.Objects; @MappedSuperclass public abstract class FinalSeminarParticipation extends DomainObject { - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne(optional = false) - private User user; + @Basic + @Enumerated(EnumType.STRING) + @Column(name = "grade") + private FinalSeminarGrade grade = null; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in tables whose entity class inherits from + // FinalSeminarParticipation class (such as final_seminar_active_participation, + // final_seminar_opposition, final_seminar_respondent) referencing other tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional = false) + @JoinColumn(name = "final_seminar_id", referencedColumnName = "id") private FinalSeminar finalSeminar; - @Enumerated(EnumType.STRING) - private FinalSeminarGrade grade = null; + @ManyToOne(optional = false) + @JoinColumn(name = "user_id", referencedColumnName = "id") + private User user; + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- + protected FinalSeminarParticipation() { + } protected FinalSeminarParticipation(User user, FinalSeminar finalSeminar) { this.user = user; this.finalSeminar = finalSeminar; } - protected FinalSeminarParticipation() { - } - - public boolean isApproved() { - return grade == FinalSeminarGrade.APPROVED; - } - - public boolean hasGrade() { - return (grade != null); - } - - public void setUser(final User user) { - this.user = user; - } - - public void setFinalSeminar(final FinalSeminar finalSeminar) { - this.finalSeminar = finalSeminar; - } - + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public User getUser() { - return this.user; - } - - public FinalSeminar getFinalSeminar() { - return this.finalSeminar; - } - public FinalSeminarGrade getGrade() { return this.grade; } @@ -67,6 +69,29 @@ public abstract class FinalSeminarParticipation extends DomainObject { this.grade = grade; } + public boolean hasGrade() { + return (grade != null); + } + + public FinalSeminar getFinalSeminar() { + return this.finalSeminar; + } + + public void setFinalSeminar(final FinalSeminar finalSeminar) { + this.finalSeminar = finalSeminar; + } + + public User getUser() { + return this.user; + } + + public void setUser(final User user) { + this.user = user; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -77,12 +102,20 @@ public abstract class FinalSeminarParticipation extends DomainObject { && Objects.equals(this.getFinalSeminar(), other.getFinalSeminar()); } - protected boolean canEqual(final Object other) { - return other instanceof FinalSeminarParticipation; - } - @Override public int hashCode() { return Objects.hash(this.getUser(), this.getFinalSeminar()); } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + + protected boolean canEqual(final Object other) { + return other instanceof FinalSeminarParticipation; + } + + public boolean isApproved() { + return grade == FinalSeminarGrade.APPROVED; + } } diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarRespondent.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarRespondent.java index 2178db68c1..92bf8ee457 100644 --- a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarRespondent.java +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarRespondent.java @@ -8,17 +8,17 @@ import jakarta.persistence.Entity; import jakarta.persistence.Table; @Entity -@Cacheable(true) @Table(name = "final_seminar_respondent") +@Cacheable(true) public class FinalSeminarRespondent extends FinalSeminarParticipation { + protected FinalSeminarRespondent() { + } + public FinalSeminarRespondent(User student, FinalSeminar finalSeminar) { super(student, finalSeminar); } - protected FinalSeminarRespondent() { - } - public Project getProject() { return getFinalSeminar().getProject(); } diff --git a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarSettings.java b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarSettings.java index b95f64e994..7a62ea83e9 100644 --- a/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarSettings.java +++ b/core/src/main/java/se/su/dsv/scipro/finalseminar/FinalSeminarSettings.java @@ -7,6 +7,7 @@ import java.util.Objects; @Entity @Cacheable(true) +@Table(name = "final_seminar_settings") public class FinalSeminarSettings extends DomainObject { public static final int DEFAULT_DAYS_AHEAD_TO_UPLOAD_THESIS = 10; public static final int DEFAULT_DAYS_AHEAD_TO_REGISTER_OPPOSITION = 3; @@ -22,25 +23,26 @@ public class FinalSeminarSettings extends DomainObject { this.id = id; } - @Basic(optional = false) + @Column(name = "days_ahead_to_create", nullable = false) private int daysAheadToCreate; - @Basic(optional = false) + @Column(name = "days_ahead_to_register_participation", nullable = false) private int daysAheadToRegisterParticipation = DEFAULT_DAYS_AHEAD_TO_REGISTER_PARTICIPATION; - @Basic(optional = false) + @Column(name = "days_ahead_to_register_opposition", nullable = false) private int daysAheadToRegisterOpposition = DEFAULT_DAYS_AHEAD_TO_REGISTER_OPPOSITION; - @Basic(optional = false) + @Column(name = "days_ahead_to_upload_thesis", nullable = false) private int daysAheadToUploadThesis = DEFAULT_DAYS_AHEAD_TO_UPLOAD_THESIS; - @Basic(optional = false) + @Column(name = "thesis_must_be_pdf", nullable = false) private boolean thesisMustBePDF = false; - @Basic(optional = true) + @Column(name = "evaluation_url", nullable = true) private String evaluationURL; @Basic(optional = false) + @Column(name = "opposition_priority_days", nullable = false) private int oppositionPriorityDays; public boolean getThesisMustBePDF() { diff --git a/core/src/main/java/se/su/dsv/scipro/finalthesis/FinalThesis.java b/core/src/main/java/se/su/dsv/scipro/finalthesis/FinalThesis.java index 894e798a5f..818bfc2b0c 100644 --- a/core/src/main/java/se/su/dsv/scipro/finalthesis/FinalThesis.java +++ b/core/src/main/java/se/su/dsv/scipro/finalthesis/FinalThesis.java @@ -21,50 +21,67 @@ import jakarta.persistence.Table; import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; -import java.util.*; +import java.util.Date; +import java.util.Objects; @Entity -@Table +@Table(name = "final_thesis") public class FinalThesis extends DomainObject { - public enum Status { - APPROVED, REJECTED, NO_DECISION - } - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne(optional = false) - @JoinColumn(name = "document_reference_id") - private FileReference document; + @Basic + @Column(name = "title_sv") + private String swedishTitle; - @ManyToOne(optional = true) - @JoinColumn(name = "text_matching_document_reference_id") - private FileReference textMatchingDocument; + @Basic + @Column(name = "title_en") + private String englishTitle; + + @Basic + @Column(name = "status") + @Enumerated(EnumType.STRING) + private Status status = Status.NO_DECISION; + + @Basic + @Column(name = "date_approved") + private Date dateApproved; + + @Basic + @Column(name = "date_rejected") + private Date dateRejected; + + @Basic + @Column(name = "rejection_comment") + private String rejectionComment; @Basic @Column(name = "text_matching_analysis") private String textMatchingAnalysis; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (final_thesis) referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = true) + @JoinColumn(name = "text_matching_document_reference_id", referencedColumnName = "id") + private FileReference textMatchingDocument; + @ManyToOne(optional = false) - @JoinColumn(name = "project_id") + @JoinColumn(name = "document_reference_id", referencedColumnName = "id") + private FileReference document; + + @ManyToOne(optional = false) + @JoinColumn(name = "project_id", referencedColumnName = "id") private Project project; - @Enumerated(EnumType.STRING) - private Status status = Status.NO_DECISION; - - private Date dateApproved; - - private Date dateRejected; - - private String englishTitle; - - private String swedishTitle; - - @Column(name = "rejection_comment") - private String rejectionComment; - + // ---------------------------------------------------------------------------------- + // JPA lifecycle method + // ---------------------------------------------------------------------------------- @PrePersist @PreUpdate void cleanTitle() { @@ -72,6 +89,126 @@ public class FinalThesis extends DomainObject { this.swedishTitle = clean(this.swedishTitle); } + + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEnglishTitle() { + return this.englishTitle; + } + + public void setEnglishTitle(String englishTitle) { + this.englishTitle = englishTitle; + } + + public String getSwedishTitle() { + return this.swedishTitle; + } + + public void setSwedishTitle(String swedishTitle) { + this.swedishTitle = swedishTitle; + } + + public Status getStatus() { + return this.status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public Date getDateApproved() { + return dateApproved; + } + + public void setDateApproved(Date dateApproved) { + this.dateApproved = dateApproved; + } + + public Date getDateRejected() { + return dateRejected; + } + + public void setDateRejected(Date dateRejected) { + this.dateRejected = dateRejected; + } + + public String getRejectionComment() { + return rejectionComment; + } + + public void setRejectionComment(String rejectionComment) { + this.rejectionComment = rejectionComment; + } + + public String getTextMatchingAnalysis() { + return textMatchingAnalysis; + } + + public void setTextMatchingAnalysis(String textMatchingAnalysis) { + this.textMatchingAnalysis = textMatchingAnalysis; + } + + public FileReference getTextMatchingDocument() { + return this.textMatchingDocument; + } + + public void setTextMatchingDocument(FileReference textMatchingDocument) { + this.textMatchingDocument = textMatchingDocument; + } + + public FileReference getDocument() { + return this.document; + } + + public void setDocument(FileReference fileDescription) { + this.document = fileDescription; + } + + public Project getProject() { + return this.project; + } + + public void setProject(Project project) { + this.project = project; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof FinalThesis)) return false; + final FinalThesis other = (FinalThesis) o; + return other.canEqual(this) + && Objects.equals(this.getDocument(), other.getDocument()) + && Objects.equals(this.getProject(), other.getProject()); + } + + @Override + public int hashCode() { + return Objects.hash(this.getDocument(), this.getProject()); + } + + @Override + public String toString() { + return "FinalThesis(id=" + this.getId() + ", fileDescription=" + this.getDocument() + ", textMatchingDocument=" + this.getTextMatchingDocument() + ", project=" + this.getProject() + ", status=" + this.getStatus() + ", dateApproved=" + this.getDateApproved() + ", dateRejected=" + this.getDateRejected() + ", englishTitle=" + this.getEnglishTitle() + ", swedishTitle=" + this.getSwedishTitle() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- private String clean(String str) { if (str == null) { return null; @@ -83,125 +220,23 @@ public class FinalThesis extends DomainObject { .trim(); } - @Override - public Long getId() { - return this.id; - } - - public FileReference getDocument() { - return this.document; - } - - public FileReference getTextMatchingDocument() { - return this.textMatchingDocument; - } - - public Project getProject() { - return this.project; - } - - public Status getStatus() { - return this.status; - } - - public String getEnglishTitle() { - return this.englishTitle; - } - - public String getSwedishTitle() { - return this.swedishTitle; - } - - public void setId(Long id) { - this.id = id; - } - - public void setDocument(FileReference fileDescription) { - this.document = fileDescription; - } - - public void setTextMatchingDocument(FileReference textMatchingDocument) { - this.textMatchingDocument = textMatchingDocument; - } - - public void setProject(Project project) { - this.project = project; - } - - public void setStatus(Status status) { - this.status = status; - } - - public void setDateApproved(Date dateApproved) { - this.dateApproved = dateApproved; - } - - public void setDateRejected(Date dateRejected) { - this.dateRejected = dateRejected; - } - - public void setEnglishTitle(String englishTitle) { - this.englishTitle = englishTitle; - } - - public void setSwedishTitle(String swedishTitle) { - this.swedishTitle = swedishTitle; - } - - public String getTextMatchingAnalysis() { - return textMatchingAnalysis; - } - - public void setTextMatchingAnalysis(String textMatchingAnalysis) { - this.textMatchingAnalysis = textMatchingAnalysis; - } - - public String getRejectionComment() { - return rejectionComment; - } - - public void setRejectionComment(String rejectionComment) { - this.rejectionComment = rejectionComment; - } - - @Override - public String toString() { - return "FinalThesis(id=" + this.getId() + ", fileDescription=" + this.getDocument() + ", textMatchingDocument=" + this.getTextMatchingDocument() + ", project=" + this.getProject() + ", status=" + this.getStatus() + ", dateApproved=" + this.getDateApproved() + ", dateRejected=" + this.getDateRejected() + ", englishTitle=" + this.getEnglishTitle() + ", swedishTitle=" + this.getSwedishTitle() + ")"; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof FinalThesis)) return false; - final FinalThesis other = (FinalThesis) o; - return other.canEqual(this) - && Objects.equals(this.getDocument(), other.getDocument()) - && Objects.equals(this.getProject(), other.getProject()); - } - protected boolean canEqual(final Object other) { return other instanceof FinalThesis; } - @Override - public int hashCode() { - return Objects.hash(this.getDocument(), this.getProject()); - } - - public boolean isRejected() { - return getStatus() == Status.REJECTED; - } - - public Date getDateRejected() { - return dateRejected; - } - - public Date getDateApproved() { - return dateApproved; - } - public LocalDate getUploadDate() { Instant instant = document.getFileDescription().getDateCreated().toInstant(); return instant.atZone(ZoneId.systemDefault()).toLocalDate(); } + + public boolean isRejected() { + return getStatus() == Status.REJECTED; + } + + // ---------------------------------------------------------------------------------- + // Nested types + // ---------------------------------------------------------------------------------- + public enum Status { + APPROVED, REJECTED, NO_DECISION + } } diff --git a/core/src/main/java/se/su/dsv/scipro/firstmeeting/ProjectFirstMeeting.java b/core/src/main/java/se/su/dsv/scipro/firstmeeting/ProjectFirstMeeting.java index acfaa134eb..759f63f781 100644 --- a/core/src/main/java/se/su/dsv/scipro/firstmeeting/ProjectFirstMeeting.java +++ b/core/src/main/java/se/su/dsv/scipro/firstmeeting/ProjectFirstMeeting.java @@ -1,37 +1,58 @@ package se.su.dsv.scipro.firstmeeting; import com.querydsl.core.annotations.QueryInit; +import jakarta.persistence.Basic; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + import se.su.dsv.scipro.activityplan.Activity; import se.su.dsv.scipro.system.DomainObject; -import jakarta.persistence.*; import java.util.Date; @Entity @Table(name = "project_first_meeting") public final class ProjectFirstMeeting extends DomainObject { + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @QueryInit("activityPlan.project") - @OneToOne(optional = false, cascade = CascadeType.ALL) - private Activity activity; - @Basic(optional = false) + @Column(name = "room") private String room; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (project_first_meeting) referencing + // other tables. + // ---------------------------------------------------------------------------------- + @OneToOne(optional = false, cascade = CascadeType.ALL) + @JoinColumn(name = "activity_id", referencedColumnName = "id") + @QueryInit("activityPlan.project") + private Activity activity; + + // ---------------------------------------------------------------------------------- + // constructor + // ---------------------------------------------------------------------------------- protected ProjectFirstMeeting() {} + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- @Override public Long getId() { return id; } - public Date getDate() { - return activity.getDate(); - } - public String getRoom() { return room; } @@ -40,10 +61,6 @@ public final class ProjectFirstMeeting extends DomainObject { this.room = room; } - public String getDescription() { - return activity.getDescription(); - } - Activity getActivity() { return activity; } @@ -51,4 +68,15 @@ public final class ProjectFirstMeeting extends DomainObject { void setActivity(Activity activity) { this.activity = activity; } + + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- + public Date getDate() { + return activity.getDate(); + } + + public String getDescription() { + return activity.getDescription(); + } } diff --git a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPost.java b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPost.java index 7740741863..aff80a655f 100644 --- a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPost.java +++ b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPost.java @@ -1,5 +1,6 @@ package se.su.dsv.scipro.forum.dataobjects; +import jakarta.persistence.Basic; import jakarta.persistence.GenerationType; import se.su.dsv.scipro.file.FileReference; import se.su.dsv.scipro.system.LazyDeletableDomainObject; @@ -15,54 +16,51 @@ import jakarta.persistence.Lob; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import java.util.*; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; @Entity @Table(name = "forum_post") public class ForumPost extends LazyDeletableDomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Lob + @Basic @Column(name = "content", nullable = false) + @Lob private String content; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (forum_post) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne - @JoinColumn(name = "user", nullable = true) - private User postedBy; - - @ManyToOne - @JoinColumn(name = "thread", nullable = false) + @JoinColumn(name = "thread_id", nullable = false) private ForumThread forumThread; + @ManyToOne + @JoinColumn(name = "user_id", nullable = true) + private User postedBy; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "forum_post" + // ---------------------------------------------------------------------------------- @OneToMany(orphanRemoval = true) - @JoinTable(name = "forum_post_file_description", - joinColumns = {@JoinColumn(name = "forum_post_id")}, + @JoinTable(name = "forum_post_file_reference", + joinColumns = {@JoinColumn(name = "forum_post_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "file_reference_id")}) private Set attachments = new HashSet<>(); - public String getSubject() { - return forumThread.getSubject(); - } - - public Set getAttachments() { - return attachments; - } - - public User getPostedBy() { - return postedBy; - } - - public String getContent() { - return content; - } - - public ForumThread getForumThread() { - return forumThread; - } - + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; @@ -72,27 +70,41 @@ public class ForumPost extends LazyDeletableDomainObject { this.id = id; } + public String getContent() { + return content; + } + public void setContent(String content) { this.content = content; } - public void setPostedBy(User postedBy) { - this.postedBy = postedBy; + public ForumThread getForumThread() { + return forumThread; } public void setForumThread(ForumThread forumThread) { this.forumThread = forumThread; } + public User getPostedBy() { + return postedBy; + } + + public void setPostedBy(User postedBy) { + this.postedBy = postedBy; + } + + public Set getAttachments() { + return attachments; + } + public void setAttachments(Set attachments) { this.attachments = attachments; } - @Override - public String toString() { - return "ForumPost(id=" + this.getId() + ", content=" + this.getContent() + ", postedBy=" + this.getPostedBy() + ", forumThread=" + this.getForumThread() + ", attachments=" + this.getAttachments() + ")"; - } - + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -106,10 +118,6 @@ public class ForumPost extends LazyDeletableDomainObject { && Objects.equals(this.getAttachments(), other.getAttachments()); } - protected boolean canEqual(final Object other) { - return other instanceof ForumPost; - } - @Override public int hashCode() { return Objects.hash( @@ -119,4 +127,22 @@ public class ForumPost extends LazyDeletableDomainObject { this.getForumThread(), this.getAttachments()); } + + @Override + public String toString() { + return "ForumPost(id=" + this.getId() + ", content=" + this.getContent() + + ", postedBy=" + this.getPostedBy() + ", forumThread=" + this.getForumThread() + + ", attachments=" + this.getAttachments() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof ForumPost; + } + + public String getSubject() { + return forumThread.getSubject(); + } } diff --git a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPostReadState.java b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPostReadState.java index 655a3baf41..eff11f8578 100644 --- a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPostReadState.java +++ b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPostReadState.java @@ -1,14 +1,21 @@ package se.su.dsv.scipro.forum.dataobjects; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.io.Serializable; @Entity -@Table(name = "forum_post_read") +@Table(name = "forum_post_read_state") public class ForumPostReadState implements Serializable { + // ---------------------------------------------------------------------------------- + // Basic and embedded JPA-mappings + // ---------------------------------------------------------------------------------- @EmbeddedId private ForumPostReadStateId id; @@ -16,6 +23,9 @@ public class ForumPostReadState implements Serializable { @Column(name = "`read`", nullable = false) private boolean read = false; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- public ForumPostReadState() { } @@ -23,6 +33,9 @@ public class ForumPostReadState implements Serializable { id = new ForumPostReadStateId(user, post); } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public ForumPostReadStateId getId() { return id; } @@ -39,4 +52,3 @@ public class ForumPostReadState implements Serializable { this.read = read; } } - diff --git a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPostReadStateId.java b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPostReadStateId.java index c596d98513..818fd9ca86 100644 --- a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPostReadStateId.java +++ b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumPostReadStateId.java @@ -11,11 +11,11 @@ import java.util.Objects; @Embeddable public class ForumPostReadStateId implements Serializable { @ManyToOne - @JoinColumn(name = "user", nullable = false) + @JoinColumn(name = "user_id", nullable = false) private User user; @ManyToOne - @JoinColumn(name = "post", nullable = false) + @JoinColumn(name = "forum_post_id", nullable = false) private ForumPost post; public ForumPostReadStateId() { diff --git a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumThread.java b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumThread.java index 3068a8fa62..aaeaf4849e 100644 --- a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumThread.java +++ b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ForumThread.java @@ -1,9 +1,21 @@ package se.su.dsv.scipro.forum.dataobjects; +import jakarta.persistence.Basic; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.OneToMany; +import jakarta.persistence.PostLoad; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.LazyDeletableDomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -13,17 +25,88 @@ import java.util.Objects; @Inheritance(strategy = InheritanceType.JOINED) public class ForumThread extends LazyDeletableDomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToMany(mappedBy = "forumThread", cascade = CascadeType.ALL, fetch = FetchType.EAGER) - private List posts = new ArrayList<>(); - @Basic @Column(name = "subject", nullable = false) private String subject; + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "thread" + // ---------------------------------------------------------------------------------- + @OneToMany(mappedBy = "forumThread", cascade = CascadeType.ALL, fetch = FetchType.EAGER) + private List posts = new ArrayList<>(); + + // ---------------------------------------------------------------------------------- + // JPA-lifecycle method + // ---------------------------------------------------------------------------------- + @PostLoad + void lazyDeletion() { + posts.removeIf(LazyDeletableDomainObject::isDeleted); + } + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public List getPosts() { + return this.posts; + } + + public void setPosts(List posts) { + this.posts = posts; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof ForumThread)) return false; + final ForumThread other = (ForumThread) o; + return other.canEqual(this) + && Objects.equals(this.getId(), other.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.getId()); + } + + @Override + public String toString() { + return "ForumThread(id=" + this.getId() + ", subject=" + this.getSubject() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof ForumThread; + } + public void addPost(ForumPost post) { posts.add(post); } @@ -32,15 +115,6 @@ public class ForumThread extends LazyDeletableDomainObject { return posts.size(); } - @PostLoad - void lazyDeletion() { - posts.removeIf(LazyDeletableDomainObject::isDeleted); - } - - public String getSubject() { - return subject; - } - public User getCreatedBy(){ return getPosts().get(0).getPostedBy(); } @@ -53,48 +127,4 @@ public class ForumThread extends LazyDeletableDomainObject { } return false; } - - @Override - public Long getId() { - return this.id; - } - - public List getPosts() { - return this.posts; - } - - public void setId(Long id) { - this.id = id; - } - - public void setPosts(List posts) { - this.posts = posts; - } - - public void setSubject(String subject) { - this.subject = subject; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof ForumThread)) return false; - final ForumThread other = (ForumThread) o; - return other.canEqual(this) - && Objects.equals(this.getId(), other.getId()); - } - - protected boolean canEqual(final Object other) { - return other instanceof ForumThread; - } - - @Override - public int hashCode() { - return Objects.hashCode(this.getId()); - } - - @Override - public String toString() { - return "ForumThread(id=" + this.getId() + ", subject=" + this.getSubject() + ")"; - } } diff --git a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/GroupThread.java b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/GroupThread.java index 5956a4d6de..ed7d45f410 100644 --- a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/GroupThread.java +++ b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/GroupThread.java @@ -1,49 +1,70 @@ package se.su.dsv.scipro.forum.dataobjects; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.group.Group; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Objects; @Entity -@Table(name = "group_thread") +@Table(name = "project_group_thread") public class GroupThread implements Serializable { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (project_group_thread) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne - @JoinColumn(name = "group_id", nullable = false) + @JoinColumn(name = "project_group_id", referencedColumnName = "id", nullable = false) private Group group; @OneToOne(cascade = CascadeType.ALL, optional = false) - @JoinColumn(name = "thread_id") + @JoinColumn(name = "thread_id", referencedColumnName = "id") private ForumThread forumThread; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } - public Group getGroup() { - return group; - } - - public ForumThread getForumThread() { - return forumThread; - } - public void setId(Long id) { this.id = id; } + public Group getGroup() { + return group; + } + public void setGroup(Group group) { this.group = group; } + public ForumThread getForumThread() { + return forumThread; + } + public void setForumThread(ForumThread forumThread) { this.forumThread = forumThread; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -55,10 +76,6 @@ public class GroupThread implements Serializable { && Objects.equals(this.getForumThread(), other.getForumThread()); } - protected boolean canEqual(final Object other) { - return other instanceof GroupThread; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getGroup(), this.getForumThread()); @@ -66,6 +83,14 @@ public class GroupThread implements Serializable { @Override public String toString() { - return "GroupThread(id=" + this.getId() + ", group=" + this.getGroup() + ", forumThread=" + this.getForumThread() + ")"; + return "GroupThread(id=" + this.getId() + ", group=" + this.getGroup() + ", forumThread=" + + this.getForumThread() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof GroupThread; } } diff --git a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ProjectThread.java b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ProjectThread.java index 32b99a8a84..ba32a9f14f 100644 --- a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ProjectThread.java +++ b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ProjectThread.java @@ -1,50 +1,70 @@ package se.su.dsv.scipro.forum.dataobjects; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Objects; @Entity @Table(name = "project_thread") public class ProjectThread implements Serializable { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(optional = false) - @JoinColumn(name = "thread_id") - private ForumThread forumThread; - + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (project_thread) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional = false) - @JoinColumn(name = "project_id") + @JoinColumn(name = "project_id", referencedColumnName = "id") private Project project; + @OneToOne(optional = false) + @JoinColumn(name = "thread_id", referencedColumnName = "id") + private ForumThread forumThread; + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } - public Project getProject() { - return project; - } - - public ForumThread getForumThread() { - return forumThread; - } - public void setId(Long id) { this.id = id; } - public void setForumThread(ForumThread forumThread) { - this.forumThread = forumThread; + public Project getProject() { + return project; } public void setProject(Project project) { this.project = project; } + public ForumThread getForumThread() { + return forumThread; + } + + public void setForumThread(ForumThread forumThread) { + this.forumThread = forumThread; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -56,10 +76,6 @@ public class ProjectThread implements Serializable { && Objects.equals(this.getProject(), other.getProject()); } - protected boolean canEqual(final Object other) { - return other instanceof ProjectThread; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getForumThread(), this.getProject()); @@ -67,6 +83,14 @@ public class ProjectThread implements Serializable { @Override public String toString() { - return "ProjectThread(id=" + this.getId() + ", forumThread=" + this.getForumThread() + ", project=" + this.getProject() + ")"; + return "ProjectThread(id=" + this.getId() + ", forumThread=" + this.getForumThread() + + ", project=" + this.getProject() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof ProjectThread; } } diff --git a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ReviewerThread.java b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ReviewerThread.java index 010a5686d6..5cce25c1ca 100644 --- a/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ReviewerThread.java +++ b/core/src/main/java/se/su/dsv/scipro/forum/dataobjects/ReviewerThread.java @@ -1,50 +1,69 @@ package se.su.dsv.scipro.forum.dataobjects; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; -import jakarta.persistence.*; import java.util.Objects; @Entity @Table(name = "reviewer_thread") public class ReviewerThread { + // ---------------------------------------------------------------------------------- + // Basic JPA-mapping + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(optional = false) - @JoinColumn(name = "thread_id") - private ForumThread forumThread; - + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (mail_event) referencing other + // tables. + // ---------------------------------------------------------------------------------- @OneToOne - @JoinColumn(name = "project_id", unique = true) + @JoinColumn(name = "project_id", referencedColumnName = "id", unique = true) private Project project; + @OneToOne(optional = false) + @JoinColumn(name = "thread_id", referencedColumnName = "id") + private ForumThread forumThread; + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return this.id; } - public ForumThread getForumThread() { - return this.forumThread; - } - - public Project getProject() { - return this.project; - } - public void setId(Long id) { this.id = id; } - public void setForumThread(ForumThread forumThread) { - this.forumThread = forumThread; + public Project getProject() { + return this.project; } public void setProject(Project project) { this.project = project; } + public ForumThread getForumThread() { + return this.forumThread; + } + + public void setForumThread(ForumThread forumThread) { + this.forumThread = forumThread; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -56,10 +75,6 @@ public class ReviewerThread { && Objects.equals(this.getProject(), other.getProject()); } - protected boolean canEqual(final Object other) { - return other instanceof ReviewerThread; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getForumThread(), this.getProject()); @@ -67,6 +82,14 @@ public class ReviewerThread { @Override public String toString() { - return "ReviewerThread(id=" + this.getId() + ", forumThread=" + this.getForumThread() + ", project=" + this.getProject() + ")"; + return "ReviewerThread(id=" + this.getId() + ", forumThread=" + this.getForumThread() + + ", project=" + this.getProject() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof ReviewerThread; } } diff --git a/core/src/main/java/se/su/dsv/scipro/forum/notifications/ForumNotification.java b/core/src/main/java/se/su/dsv/scipro/forum/notifications/ForumNotification.java index 3bc39f38ab..fe2bc877e4 100644 --- a/core/src/main/java/se/su/dsv/scipro/forum/notifications/ForumNotification.java +++ b/core/src/main/java/se/su/dsv/scipro/forum/notifications/ForumNotification.java @@ -1,26 +1,44 @@ package se.su.dsv.scipro.forum.notifications; +import jakarta.persistence.Embeddable; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; +import jakarta.persistence.Table; import se.su.dsv.scipro.forum.dataobjects.ForumPost; import se.su.dsv.scipro.notifications.dataobject.NotificationEvent; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Objects; @Entity @Table(name = "forum_notification") class ForumNotification { + // ---------------------------------------------------------------------------------- + // Embedded JPA-mapping + // ---------------------------------------------------------------------------------- @EmbeddedId private Id id = new Id(); + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (forum_notification) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional = false) + @JoinColumn(name = "forum_post_id", referencedColumnName = "id") @MapsId("forumPostId") private ForumPost forumPost; @ManyToOne(optional = false) + @JoinColumn(name = "notification_data_id") @MapsId("notificationEventId") private NotificationEvent notificationEvent; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected ForumNotification() { } // JPA ForumNotification(final ForumPost forumPost, final NotificationEvent notificationEvent) { @@ -28,6 +46,9 @@ class ForumNotification { this.notificationEvent = notificationEvent; } + // ---------------------------------------------------------------------------------- + // Properties (Getters) + // ---------------------------------------------------------------------------------- public ForumPost getForumPost() { return forumPost; } @@ -36,6 +57,9 @@ class ForumNotification { return notificationEvent; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -47,10 +71,6 @@ class ForumNotification { && Objects.equals(this.getNotificationEvent(), other.getNotificationEvent()); } - protected boolean canEqual(final Object other) { - return other instanceof ForumNotification; - } - @Override public int hashCode() { return Objects.hash(this.id, this.getForumPost(), this.getNotificationEvent()); @@ -58,9 +78,20 @@ class ForumNotification { @Override public String toString() { - return "ForumNotification(id=" + this.id + ", forumPost=" + this.getForumPost() + ", notificationEvent=" + this.getNotificationEvent() + ")"; + return "ForumNotification(id=" + this.id + ", forumPost=" + this.getForumPost() + + ", notificationEvent=" + this.getNotificationEvent() + ")"; } + // ---------------------------------------------------------------------------------- + // Other method + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof ForumNotification; + } + + // ---------------------------------------------------------------------------------- + // Nested type + // ---------------------------------------------------------------------------------- @Embeddable static class Id implements Serializable { private Long forumPostId; @@ -103,7 +134,8 @@ class ForumNotification { @Override public String toString() { - return "ForumNotification.Id(forumPostId=" + this.getForumPostId() + ", notificationEventId=" + this.getNotificationEventId() + ")"; + return "ForumNotification.Id(forumPostId=" + this.getForumPostId() + ", notificationEventId=" + + this.getNotificationEventId() + ")"; } } } diff --git a/core/src/main/java/se/su/dsv/scipro/generalsystemsettings/GeneralSystemSettings.java b/core/src/main/java/se/su/dsv/scipro/generalsystemsettings/GeneralSystemSettings.java index b7f7bc0b0b..511fd841b4 100755 --- a/core/src/main/java/se/su/dsv/scipro/generalsystemsettings/GeneralSystemSettings.java +++ b/core/src/main/java/se/su/dsv/scipro/generalsystemsettings/GeneralSystemSettings.java @@ -14,81 +14,86 @@ public class GeneralSystemSettings extends DomainObject { @Id private Long id = null; - @Basic + @Column(name = "daisy_profile_link_base_url") private String daisyProfileLinkBaseURL; - @Basic + @Column(name = "daisy_select_research_area_url") private String daisySelectResearchAreaURL; @ElementCollection - @CollectionTable(name = "general_system_settings_alarm_recipients") + @CollectionTable(name = "general_system_settings_alarm_recipient", + joinColumns = @JoinColumn(name = "general_system_settings_id", referencedColumnName = "id")) @Column(name = "mail") private List alarmMails = new ArrayList<>(); @ElementCollection - @CollectionTable(name = "general_system_settings_supervisor_change_recipients") + @CollectionTable(name = "general_system_settings_supervisor_change_recipient", + joinColumns = @JoinColumn(name = "general_system_settings_id", referencedColumnName = "id")) @Column(name = "mail") private List supervisorChangeMails = new ArrayList<>(); - @Basic(optional = true) + @Column(name = "project_partner_days_to_live", nullable = true) private int projectPartnerDaysToLive; - @Basic(optional = false) + @Column(name = "mail_notifications", nullable = false) private boolean mailNotifications = true; - @Basic(optional = false) + @Column(name = "mail_from_name", nullable = false) private String mailFromName = "SciPro"; - @Basic(optional = false) + @Column(name = "system_from_mail", nullable = false) private String systemFromMail = "noreply-scipro@dsv.su.se"; - @Basic(optional = false) + @Column(name = "smtp_server", nullable = false) private String smtpServer = "localhost"; + @Column(name = "peer_display_latest_reviews") private boolean peerDisplayLatestReviews = true; - @Basic(optional = false) + @Column(name = "number_of_latest_reviews_displayed", nullable = false) private int numberOfLatestReviewsDisplayed = DEFAULT_NUMER_OF_LATEST_REVIEWS_DISPLAYED; - @Basic(optional = false) + @Column(name = "public_reviews_activated", nullable = false) private boolean publicReviewsActivated = true; - @Basic(optional = false) + @Column(name = "peer_download_enabled", nullable = false) private boolean peerDownloadEnabled = true; - @Basic(optional = false) + @Column(name = "scipro_url", nullable = false) private String sciproURL = "http://localhost:8080/"; - @Basic(optional = false) + @Column(name = "show_single_sign_on", nullable = false) private boolean showSingleSignOn = true; @ElementCollection @Enumerated(EnumType.STRING) - @JoinTable(name = "general_system_settings_system_modules") + @CollectionTable(name = "general_system_settings_system_module", + joinColumns = @JoinColumn(name = "general_system_settings_id", referencedColumnName = "id")) + @Column(name = "system_module") private Set systemModules = EnumSet.allOf(SystemModule.class); - @Basic(optional = true) + @Column(name = "match_responsible_mail", nullable = true) private String matchResponsibleMail = ""; - @Basic(optional = true) + @Column(name = "reviewer_support_mail", nullable = true) private String reviewerSupportMail; - @Basic(optional = true) + @Column(name = "thesis_support_mail", nullable = true) private String thesisSupportMail; - @Basic(optional = true) + @Column(name = "external_room_booking_url", nullable = true) private String externalRoomBookingURL; - @Basic(optional = true) + @Column(name = "external_getting_started_with_idea_url", nullable = true) private String externalGettingStartedWithIdeaURL; - @Basic(optional = true) + @Column(name = "external_grading_url", nullable = true) private String externalGradingURL; - @Basic(optional = false) + @Column(name = "final_survey_available", nullable = false) private boolean finalSurveyAvailable = false; - @Basic + @Column(name = "active_project_idea_support_mail") private String activeProjectIdeaSupportMail; public GeneralSystemSettings() { diff --git a/core/src/main/java/se/su/dsv/scipro/grading/ApprovedEvent.java b/core/src/main/java/se/su/dsv/scipro/grading/ApprovedEvent.java index dfe7e5b08b..88160eb8a9 100644 --- a/core/src/main/java/se/su/dsv/scipro/grading/ApprovedEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/grading/ApprovedEvent.java @@ -16,20 +16,31 @@ import java.time.Instant; import java.util.Objects; @Entity -@Table(name = "grading_history_approvals") +@Table(name = "grading_history_approval") public class ApprovedEvent { + + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - @JoinColumn(name = "project_id") - private Project project; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "`when`") private Instant when; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (grading_history_rejections) referencing + // other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne + @JoinColumn(name = "project_id") + private Project project; + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } @@ -38,14 +49,6 @@ public class ApprovedEvent { this.id = id; } - public Project getProject() { - return project; - } - - public void setProject(Project project) { - this.project = project; - } - public Instant getWhen() { return when; } @@ -54,6 +57,17 @@ public class ApprovedEvent { this.when = when; } + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(Object o) { if (this == o) return true; @@ -70,10 +84,7 @@ public class ApprovedEvent { @Override public String toString() { - return "ApprovedEvent{" + - "id=" + id + - ", project=" + project + - ", when=" + when + - '}'; + return "ApprovedEvent{" + "id=" + id + ", project=" + project + + ", when=" + when + '}'; } } diff --git a/core/src/main/java/se/su/dsv/scipro/grading/NationalSubjectCategory.java b/core/src/main/java/se/su/dsv/scipro/grading/NationalSubjectCategory.java index 26323389d8..c2ec2aa67e 100644 --- a/core/src/main/java/se/su/dsv/scipro/grading/NationalSubjectCategory.java +++ b/core/src/main/java/se/su/dsv/scipro/grading/NationalSubjectCategory.java @@ -12,21 +12,20 @@ import java.util.Objects; @Entity @Table(name = "national_subject_category") public class NationalSubjectCategory { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = jakarta.persistence.GenerationType.IDENTITY) @Column(name = "id") private Long id; @Basic - @Column(name = "external_id") - private Integer externalId; - - @Basic - @Column(name = "swedish_name") + @Column(name = "name_sv") private String swedishName; @Basic - @Column(name = "english_name") + @Column(name = "name_en") private String englishName; @Basic @@ -37,9 +36,19 @@ public class NationalSubjectCategory { @Column(name = "preselected") private boolean preselected; + @Basic + @Column(name = "external_id") + private Integer externalId; + + // ---------------------------------------------------------------------------------- + // Constructor + // ---------------------------------------------------------------------------------- public NationalSubjectCategory() { } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } @@ -48,14 +57,6 @@ public class NationalSubjectCategory { this.id = id; } - public Integer getExternalId() { - return externalId; - } - - public void setExternalId(Integer externalId) { - this.externalId = externalId; - } - public String getSwedishName() { return swedishName; } @@ -88,6 +89,17 @@ public class NationalSubjectCategory { this.preselected = preselected; } + public Integer getExternalId() { + return externalId; + } + + public void setExternalId(Integer externalId) { + this.externalId = externalId; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(Object o) { if (this == o) { diff --git a/core/src/main/java/se/su/dsv/scipro/grading/PublicationMetadata.java b/core/src/main/java/se/su/dsv/scipro/grading/PublicationMetadata.java index 87b0a82f6c..2fe7236e6c 100644 --- a/core/src/main/java/se/su/dsv/scipro/grading/PublicationMetadata.java +++ b/core/src/main/java/se/su/dsv/scipro/grading/PublicationMetadata.java @@ -17,34 +17,44 @@ import java.util.Objects; @Entity @Table(name = "publication_metadata") public class PublicationMetadata { - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(optional = false) - private Project project; - @Basic - @Column(name = "abstract_swedish") + @Column(name = "abstract_sv") private String abstractSwedish; @Basic - @Column(name = "abstract_english") + @Column(name = "abstract_en") private String abstractEnglish; @Basic - @Column(name = "keywords_swedish") + @Column(name = "keywords_sv") private String keywordsSwedish; @Basic - @Column(name = "keywords_english") + @Column(name = "keywords_en") private String keywordsEnglish; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (publication_metadata) referencing + // other tables. + // ---------------------------------------------------------------------------------- @ManyToOne @JoinColumn(name = "national_subject_category_id") private NationalSubjectCategory nationalSubjectCategory;; + @OneToOne(optional = false) + @JoinColumn(name = "project_id") + private Project project; + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } @@ -53,14 +63,6 @@ public class PublicationMetadata { this.id = id; } - public Project getProject() { - return project; - } - - public void setProject(Project project) { - this.project = project; - } - public String getAbstractSwedish() { return abstractSwedish; } @@ -101,19 +103,17 @@ public class PublicationMetadata { this.nationalSubjectCategory = nationalSubjectCategory; } - @Override - public String toString() { - return "PublicationMetadata{" + - "id=" + id + - ", project=" + project + - ", abstractSwedish='" + abstractSwedish + '\'' + - ", abstractEnglish='" + abstractEnglish + '\'' + - ", keywordsSwedish='" + keywordsSwedish + '\'' + - ", keywordsEnglish='" + keywordsEnglish + '\'' + - ", nationalSubjectCategory=" + nationalSubjectCategory + '\'' + - '}'; + public Project getProject() { + return project; } + public void setProject(Project project) { + this.project = project; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(Object o) { return o instanceof PublicationMetadata that && @@ -124,4 +124,15 @@ public class PublicationMetadata { public int hashCode() { return Objects.hashCode(id); } + + @Override + public String toString() { + return "PublicationMetadata{" + "id=" + id + ", project=" + project + + ", abstractSwedish='" + abstractSwedish + '\'' + + ", abstractEnglish='" + abstractEnglish + '\'' + + ", keywordsSwedish='" + keywordsSwedish + '\'' + + ", keywordsEnglish='" + keywordsEnglish + '\'' + + ", nationalSubjectCategory=" + nationalSubjectCategory + '\'' + + '}'; + } } diff --git a/core/src/main/java/se/su/dsv/scipro/grading/RejectionEvent.java b/core/src/main/java/se/su/dsv/scipro/grading/RejectionEvent.java index 745eaf14a8..d7a24907e3 100644 --- a/core/src/main/java/se/su/dsv/scipro/grading/RejectionEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/grading/RejectionEvent.java @@ -17,23 +17,35 @@ import java.time.Instant; import java.util.Objects; @Entity -@Table(name = "grading_history_rejections") +@Table(name = "grading_history_rejection") public class RejectionEvent { + + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - @JoinColumn(name = "project_id") - private Project project; + @Basic + @Column(name = "reason") + private String reason; @Temporal(TemporalType.TIMESTAMP) @Column(name = "`when`") private Instant when; - @Basic - private String reason; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (grading_history_rejections) referencing + // other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne + @JoinColumn(name = "project_id") + private Project project; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } @@ -42,22 +54,6 @@ public class RejectionEvent { this.id = id; } - public Project getProject() { - return project; - } - - public void setProject(Project project) { - this.project = project; - } - - public Instant getWhen() { - return when; - } - - public void setWhen(Instant when) { - this.when = when; - } - public String getReason() { return reason; } @@ -66,6 +62,25 @@ public class RejectionEvent { this.reason = reason; } + public Instant getWhen() { + return when; + } + + public void setWhen(Instant when) { + this.when = when; + } + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/core/src/main/java/se/su/dsv/scipro/grading/SubmissionEvent.java b/core/src/main/java/se/su/dsv/scipro/grading/SubmissionEvent.java index 664c1e6bcf..fd88070c36 100644 --- a/core/src/main/java/se/su/dsv/scipro/grading/SubmissionEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/grading/SubmissionEvent.java @@ -18,27 +18,38 @@ import java.time.Instant; import java.util.Objects; @Entity -@Table(name = "grading_history_submissions") +@Table(name = "grading_history_submission") public class SubmissionEvent { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - @JoinColumn(name = "project_id") - private Project project; - - @ManyToOne - @JoinColumn(name = "author_id") - private User author; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "`when`") private Instant when; @Basic + @Column(name = "corrections") private String corrections; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (grading_history_submission) referencing + // other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + + @ManyToOne + @JoinColumn(name = "author_user_id", referencedColumnName = "id") + private User author; + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } @@ -47,22 +58,6 @@ public class SubmissionEvent { this.id = id; } - public Project getProject() { - return project; - } - - public void setProject(Project project) { - this.project = project; - } - - public User getAuthor() { - return author; - } - - public void setAuthor(User user) { - this.author = user; - } - public Instant getWhen() { return when; } @@ -79,6 +74,25 @@ public class SubmissionEvent { this.corrections = corrections; } + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + public User getAuthor() { + return author; + } + + public void setAuthor(User user) { + this.author = user; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(Object o) { if (this == o) return true; @@ -97,11 +111,8 @@ public class SubmissionEvent { @Override public String toString() { - return "RejectionEvent{" + - "id=" + id + - ", project=" + project + - ", author=" + author + - ", when=" + when + + return "RejectionEvent{" + "id=" + id + ", project=" + project + + ", author=" + author + ", when=" + when + ", corrections='" + corrections + '\'' + '}'; } diff --git a/core/src/main/java/se/su/dsv/scipro/group/Group.java b/core/src/main/java/se/su/dsv/scipro/group/Group.java index c85082e740..11aecf59e8 100644 --- a/core/src/main/java/se/su/dsv/scipro/group/Group.java +++ b/core/src/main/java/se/su/dsv/scipro/group/Group.java @@ -18,30 +18,124 @@ public class Group extends DomainObject { public static final int STRING_MAX_LENGTH = 255; + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(length = STRING_MAX_LENGTH) @Basic(optional = false) + @Column(name = "title", length = STRING_MAX_LENGTH) private String title; @Basic(optional = true) + @Column(name = "description") private String description; + @Basic + @Column(name = "active") + private boolean active = true; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (project_group) referencing other tables. + // ---------------------------------------------------------------------------------- //Creator, should be a supervisor @ManyToOne(optional = false) - @JoinColumn(name = "user_id") + @JoinColumn(name = "user_id", referencedColumnName = "id") private User user; + // ---------------------------------------------------------------------------------- + // @ManyToMany JPA-mappings + // ---------------------------------------------------------------------------------- @ManyToMany - @JoinTable( - name = "project_group_project", - joinColumns = @JoinColumn(name = "project_group_id"), - inverseJoinColumns = @JoinColumn(name = "project_id")) + @JoinTable(name = "project_group_project", + joinColumns = @JoinColumn(name = "project_group_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id")) private Set projects = new HashSet<>(); - private boolean active = true; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.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 this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isActive() { + return this.active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public User getUser() { + return this.user; + } + + public void setUser(User user) { + this.user = user; + } + + public Set getProjects() { + return projects; + } + + public void setProjects(Set projects) { + this.projects = projects; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Group)) return false; + final Group other = (Group) o; + return other.canEqual(this) + && Objects.equals(this.getId(), other.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.getId()); + } + + @Override + public String toString() { + return "Group(id=" + this.getId() + ", title=" + this.getTitle() + ", description=" + + this.getDescription() + ", user=" + this.getUser() + ", projects=" + + this.getProjects() + ", active=" + this.isActive() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof Group; + } public boolean isAuthor(final User user) { for (Project project : projects) { @@ -58,76 +152,4 @@ public class Group extends DomainObject { .filter(member -> member.getType() != Member.Type.REVIEWER) .toList(); } - - public Set getProjects() { - return projects; - } - - public String getTitle() { - return title; - } - - @Override - public Long getId() { - return this.id; - } - - public String getDescription() { - return this.description; - } - - public User getUser() { - return this.user; - } - - public boolean isActive() { - return this.active; - } - - public void setId(Long id) { - this.id = id; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setUser(User user) { - this.user = user; - } - - public void setProjects(Set projects) { - this.projects = projects; - } - - public void setActive(boolean active) { - this.active = active; - } - - @Override - public String toString() { - return "Group(id=" + this.getId() + ", title=" + this.getTitle() + ", description=" + this.getDescription() + ", user=" + this.getUser() + ", projects=" + this.getProjects() + ", active=" + this.isActive() + ")"; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof Group)) return false; - final Group other = (Group) o; - return other.canEqual(this) - && Objects.equals(this.getId(), other.getId()); - } - - protected boolean canEqual(final Object other) { - return other instanceof Group; - } - - @Override - public int hashCode() { - return Objects.hashCode(this.getId()); - } -} \ No newline at end of file +} diff --git a/core/src/main/java/se/su/dsv/scipro/integration/activityfinalseminar/ActivityFinalSeminar.java b/core/src/main/java/se/su/dsv/scipro/integration/activityfinalseminar/ActivityFinalSeminar.java index f5bd35bd82..7a34082b32 100644 --- a/core/src/main/java/se/su/dsv/scipro/integration/activityfinalseminar/ActivityFinalSeminar.java +++ b/core/src/main/java/se/su/dsv/scipro/integration/activityfinalseminar/ActivityFinalSeminar.java @@ -1,30 +1,49 @@ package se.su.dsv.scipro.integration.activityfinalseminar; +import jakarta.persistence.AttributeOverride; +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; +import jakarta.persistence.Table; + import se.su.dsv.scipro.activityplan.Activity; import se.su.dsv.scipro.finalseminar.FinalSeminar; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Objects; @Entity @Table(name = "activity_final_seminar") class ActivityFinalSeminar { + // ---------------------------------------------------------------------------------- + // embedded JPA-mappings + // ---------------------------------------------------------------------------------- @EmbeddedId @AttributeOverride(name = "activityId", column = @Column(name = "activity_id")) @AttributeOverride(name = "finalSeminarId", column = @Column(name = "final_seminar_id")) private Id id = new Id(); + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (activity_final_seminiar) referencing + // other tables. + // ---------------------------------------------------------------------------------- @ManyToOne @MapsId("activityId") - @JoinColumn(name = "activity_id") + @JoinColumn(name = "activity_id", referencedColumnName = "id") private Activity activity; @ManyToOne @MapsId("finalSeminarId") - @JoinColumn(name = "final_seminar_id") + @JoinColumn(name = "final_seminar_id", referencedColumnName = "id") private FinalSeminar finalSeminar; + // ---------------------------------------------------------------------------------- + // constructor + // ---------------------------------------------------------------------------------- protected ActivityFinalSeminar() { // JPA } @@ -34,6 +53,9 @@ class ActivityFinalSeminar { this.finalSeminar = finalSeminar; } + // ---------------------------------------------------------------------------------- + // getters + // ---------------------------------------------------------------------------------- public Id getId() { return this.id; } @@ -46,6 +68,9 @@ class ActivityFinalSeminar { return this.finalSeminar; } + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -57,10 +82,6 @@ class ActivityFinalSeminar { && Objects.equals(this.getFinalSeminar(), other.getFinalSeminar()); } - protected boolean canEqual(final Object other) { - return other instanceof ActivityFinalSeminar; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getActivity(), this.getFinalSeminar()); @@ -71,6 +92,13 @@ class ActivityFinalSeminar { return "ActivityFinalSeminar(id=" + this.getId() + ", activity=" + this.getActivity() + ", finalSeminar=" + this.getFinalSeminar() + ")"; } + protected boolean canEqual(final Object other) { + return other instanceof ActivityFinalSeminar; + } + + // ---------------------------------------------------------------------------------- + // nested class + // ---------------------------------------------------------------------------------- @Embeddable static class Id implements Serializable { private Long activityId; diff --git a/core/src/main/java/se/su/dsv/scipro/integration/activityforum/ActivityThread.java b/core/src/main/java/se/su/dsv/scipro/integration/activityforum/ActivityThread.java index 89d7f0ee43..a890466fc5 100644 --- a/core/src/main/java/se/su/dsv/scipro/integration/activityforum/ActivityThread.java +++ b/core/src/main/java/se/su/dsv/scipro/integration/activityforum/ActivityThread.java @@ -1,27 +1,44 @@ package se.su.dsv.scipro.integration.activityforum; +import jakarta.persistence.Embeddable; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; +import jakarta.persistence.Table; + import se.su.dsv.scipro.activityplan.Activity; import se.su.dsv.scipro.forum.dataobjects.ProjectThread; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Objects; @Entity @Table(name = "activity_thread") class ActivityThread { + // ---------------------------------------------------------------------------------- + // basic and embedded JPA-mappings + // ---------------------------------------------------------------------------------- @EmbeddedId private Id id = new Id(); - @ManyToOne - @MapsId("threadId") - @JoinColumn(name = "project_thread_id") - private ProjectThread thread; - + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (activity_thread) referencing other tables. + // ---------------------------------------------------------------------------------- @ManyToOne @MapsId("activityId") + @JoinColumn(name = "activity_id", referencedColumnName = "id") private Activity activity; + @ManyToOne + @MapsId("threadId") + @JoinColumn(name = "project_thread_id", referencedColumnName = "id") + private ProjectThread thread; + + // ---------------------------------------------------------------------------------- + // constructor + // ---------------------------------------------------------------------------------- protected ActivityThread() { // JPA } @@ -31,6 +48,9 @@ class ActivityThread { this.activity = activity; } + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- public Id getId() { return this.id; } @@ -43,6 +63,9 @@ class ActivityThread { return this.activity; } + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -54,10 +77,6 @@ class ActivityThread { && Objects.equals(this.getActivity(), other.getActivity()); } - protected boolean canEqual(final Object other) { - return other instanceof ActivityThread; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getThread(), this.getActivity()); @@ -68,6 +87,13 @@ class ActivityThread { return "ActivityThread(id=" + this.getId() + ", thread=" + this.getThread() + ", activity=" + this.getActivity() + ")"; } + protected boolean canEqual(final Object other) { + return other instanceof ActivityThread; + } + + // ---------------------------------------------------------------------------------- + // nested class + // ---------------------------------------------------------------------------------- @Embeddable static class Id implements Serializable { private Long threadId; diff --git a/core/src/main/java/se/su/dsv/scipro/mail/MailEvent.java b/core/src/main/java/se/su/dsv/scipro/mail/MailEvent.java index 200d362663..a8b99efd4d 100755 --- a/core/src/main/java/se/su/dsv/scipro/mail/MailEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/mail/MailEvent.java @@ -1,5 +1,6 @@ package se.su.dsv.scipro.mail; +import jakarta.persistence.CollectionTable; import jakarta.persistence.GenerationType; import se.su.dsv.scipro.file.FileReference; import se.su.dsv.scipro.system.DomainObject; @@ -19,61 +20,80 @@ import jakarta.persistence.Lob; import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import java.util.*; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; @Entity @Table(name = "mail_event") @Cacheable(false) public class MailEvent extends DomainObject { public static final int STRING_MAX_LENGTH = 255; + + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @JoinTable( - name = "mail_event_recipients", - joinColumns = @JoinColumn(name = "mail_event_id"), - inverseJoinColumns = @JoinColumn(name = "recipients_id")) - @ManyToMany(fetch = FetchType.EAGER) - private Set recipients = new HashSet<>(); - - @ElementCollection - private Set nonUserRecipients = new HashSet<>(); - - @Column(length = STRING_MAX_LENGTH) @Basic(optional = false) + @Column(name = "subject", length = STRING_MAX_LENGTH) private String subject; - @Column(length = STRING_MAX_LENGTH) @Basic(optional = true) + @Column(name = "from_name", length = STRING_MAX_LENGTH) private String fromName; - @Column(length = STRING_MAX_LENGTH) @Basic(optional = true) + @Column(name = "from_email", length = STRING_MAX_LENGTH) private String fromEmail; - @Lob @Basic(optional = false) + @Column(name = "message_body") + @Lob private String messageBody; @Basic(optional = false) + @Column(name = "sent") private boolean sent = false; @Basic(optional = true) + @Column(name = "message_id") private String messageID; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (mail_event) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional = true) - @JoinColumn(name = "attachment_reference_id") + @JoinColumn(name = "attachment_file_reference_id", referencedColumnName = "id") private FileReference attachment; + // ---------------------------------------------------------------------------------- + // @ManyToMany JPA-mappings + // ---------------------------------------------------------------------------------- + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "mail_event_recipient", + joinColumns = @JoinColumn(name = "mail_event_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "recipient_id", referencedColumnName = "id")) + private Set recipients = new HashSet<>(); + + @ElementCollection + @CollectionTable(name = "mail_event_non_user_recipient", + joinColumns = @JoinColumn(name = "mail_event_id", referencedColumnName = "id")) + @Column(name = "non_user_recipient") + private Set nonUserRecipients = new HashSet<>(); + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- public MailEvent() { } - public MailEvent( - final String subject, - final String messageBody, - final User recipient, - final String fromName, + public MailEvent(final String subject, final String messageBody, final User recipient, final String fromName, final String fromEmail) { this.subject = subject; this.messageBody = messageBody; @@ -82,13 +102,8 @@ public class MailEvent extends DomainObject { this.fromEmail = fromEmail; } - public MailEvent( - final String subject, - final String messageBody, - final Collection recipients, - final String fromName, - final String fromEmail - ) { + public MailEvent(final String subject, final String messageBody, final Collection recipients, + final String fromName, final String fromEmail) { this.subject = subject; this.messageBody = messageBody; this.recipients.addAll(recipients); @@ -96,35 +111,124 @@ public class MailEvent extends DomainObject { this.fromEmail = fromEmail; } - public boolean isSent() { - return sent; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; } - public void markSent(final String messageID) { - this.messageID = messageID; - this.sent = true; + public void setId(Long id) { + this.id = id; } - public Set getRecipients() { - return recipients; - } - - public void setMessageBody(String messageBody) { - this.messageBody = messageBody; + public String getSubject() { + return this.subject; } public void setSubject(String subject) { this.subject = subject; } + public String getFromName() { + return this.fromName; + } + public void setFromName(String fromName) { this.fromName = fromName; } + public String getFromEmail() { + return this.fromEmail; + } + public void setFromEmail(String fromEmail) { this.fromEmail = fromEmail; } + public String getMessageBody() { + return this.messageBody; + } + + public void setMessageBody(String messageBody) { + this.messageBody = messageBody; + } + + public boolean isSent() { + return sent; + } + + public void setSent(boolean sent) { + this.sent = sent; + } + + public String getMessageID() { + return this.messageID; + } + + public void setMessageID(String messageID) { + this.messageID = messageID; + } + + public FileReference getAttachment() { + return this.attachment; + } + + public void setAttachment(FileReference attachment) { + this.attachment = attachment; + } + + public Set getRecipients() { + return recipients; + } + + public void setRecipients(Set recipients) { + this.recipients = recipients; + } + + public Set getNonUserRecipients() { + return this.nonUserRecipients; + } + + public void setNonUserRecipients(Set nonUserRecipients) { + this.nonUserRecipients = nonUserRecipients; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof MailEvent)) return false; + final MailEvent other = (MailEvent) o; + return other.canEqual(this) + && Objects.equals(this.getId(), other.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.getId()); + } + + @Override + public String toString() { + return "MailEvent(id=" + this.getId() + ", recipients=" + this.getRecipients() + + ", nonUserRecipients=" + this.getNonUserRecipients() + ", subject=" + + this.getSubject() + ", fromName=" + this.getFromName() + + ", fromEmail=" + this.getFromEmail() + ", messageBody=" + this.getMessageBody() + + ", sent=" + this.isSent() + ", messageID=" + this.getMessageID() + + ", attachment=" + this.getAttachment() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof MailEvent; + } + public void addRecipients(final Iterable recipients) { for (Recipient recipient : recipients) { recipient.accept(new RecipientVisitor() { @@ -141,83 +245,8 @@ public class MailEvent extends DomainObject { } } - @Override - public Long getId() { - return this.id; - } - - public Set getNonUserRecipients() { - return this.nonUserRecipients; - } - - public String getSubject() { - return this.subject; - } - - public String getFromName() { - return this.fromName; - } - - public String getFromEmail() { - return this.fromEmail; - } - - public String getMessageBody() { - return this.messageBody; - } - - public String getMessageID() { - return this.messageID; - } - - public FileReference getAttachment() { - return this.attachment; - } - - public void setId(Long id) { - this.id = id; - } - - public void setRecipients(Set recipients) { - this.recipients = recipients; - } - - public void setNonUserRecipients(Set nonUserRecipients) { - this.nonUserRecipients = nonUserRecipients; - } - - public void setSent(boolean sent) { - this.sent = sent; - } - - public void setMessageID(String messageID) { + public void markSent(final String messageID) { this.messageID = messageID; - } - - public void setAttachment(FileReference attachment) { - this.attachment = attachment; - } - - @Override - public String toString() { - return "MailEvent(id=" + this.getId() + ", recipients=" + this.getRecipients() + ", nonUserRecipients=" + this.getNonUserRecipients() + ", subject=" + this.getSubject() + ", fromName=" + this.getFromName() + ", fromEmail=" + this.getFromEmail() + ", messageBody=" + this.getMessageBody() + ", sent=" + this.isSent() + ", messageID=" + this.getMessageID() + ", attachment=" + this.getAttachment() + ")"; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof MailEvent)) return false; - final MailEvent other = (MailEvent) o; - return other.canEqual(this) - && Objects.equals(this.getId(), other.getId()); - } - - protected boolean canEqual(final Object other) { - return other instanceof MailEvent; - } - - @Override - public int hashCode() { - return Objects.hashCode(this.getId()); + this.sent = true; } } diff --git a/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriod.java b/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriod.java index 6955d28d2d..d3c7a21e50 100755 --- a/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriod.java +++ b/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriod.java @@ -1,17 +1,30 @@ package se.su.dsv.scipro.match; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; + import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.ProjectType; -import jakarta.persistence.*; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.*; - @Entity @Cacheable(true) -@Table(name="ApplicationPeriod") +@Table(name="application_period") public class ApplicationPeriod extends DomainObject { @Id @@ -23,17 +36,16 @@ public class ApplicationPeriod extends DomainObject { private String name; - @Basic + @Column(name = "start_date") private LocalDate startDate = LocalDate.now(); - @Basic + @Column(name = "end_date") private LocalDate endDate = LocalDate.now(); - @Basic - @Column(name = "courseStartDate") + @Column(name = "course_start_date") private LocalDateTime courseStartDateTime = LocalDate.now().atTime(8, 0); - @Basic + @Column(name = "course_end_date") private LocalDate courseEndDate; @OneToMany(fetch = FetchType.LAZY, mappedBy = "applicationPeriod", cascade=CascadeType.ALL, orphanRemoval=true) diff --git a/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriodExemption.java b/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriodExemption.java index 717d71f294..82197dc73d 100644 --- a/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriodExemption.java +++ b/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriodExemption.java @@ -1,15 +1,23 @@ package se.su.dsv.scipro.match; -import se.su.dsv.scipro.system.User; - -import jakarta.persistence.*; import java.io.Serializable; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Objects; +import jakarta.persistence.AttributeOverride; +import jakarta.persistence.Column; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; +import jakarta.persistence.Table; + +import se.su.dsv.scipro.system.User; + @Entity -@Table(name = "applicationperiodexemption") +@Table(name = "application_period_exemption") public class ApplicationPeriodExemption implements Serializable { public enum Type { SUBMIT_STUDENT_IDEA(true), @@ -39,16 +47,19 @@ public class ApplicationPeriodExemption implements Serializable { @MapsId("applicationPeriodId") @ManyToOne(optional = false) - @JoinColumn(name = "applicationPeriodId") + @JoinColumn(name = "application_period_id") private ApplicationPeriod applicationPeriod; + @Column(name = "end_date") private LocalDate endDate; private String comment; @ManyToOne(optional = false) + @JoinColumn(name = "granted_by_id") private User grantedBy; + @Column(name = "granted_on") private LocalDateTime grantedOn; public ApplicationPeriodExemptionId getApplicationperiodexemptionId() { diff --git a/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriodProjectType.java b/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriodProjectType.java index 0d9a6f0b91..eac5ccfbc2 100644 --- a/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriodProjectType.java +++ b/core/src/main/java/se/su/dsv/scipro/match/ApplicationPeriodProjectType.java @@ -1,5 +1,7 @@ package se.su.dsv.scipro.match; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Table; import se.su.dsv.scipro.activityplan.ActivityPlanTemplate; import se.su.dsv.scipro.system.ProjectType; @@ -10,19 +12,23 @@ import jakarta.persistence.MapsId; import java.io.Serializable; @Entity +@Table(name = "application_period_project_type") public class ApplicationPeriodProjectType implements Serializable { @EmbeddedId private ApplicationPeriodProjectTypeId applicationPeriodProjectTypeId = new ApplicationPeriodProjectTypeId(); @MapsId("applicationPeriodId") @ManyToOne + @JoinColumn(name = "application_period_id") private ApplicationPeriod applicationPeriod; @MapsId("projectTypeId") @ManyToOne + @JoinColumn(name = "project_type_id") private ProjectType projectType; @ManyToOne(optional = true) + @JoinColumn(name = "activity_plan_template_id") private ActivityPlanTemplate activityPlanTemplate; protected ApplicationPeriodProjectType() {} diff --git a/core/src/main/java/se/su/dsv/scipro/match/FirstMeeting.java b/core/src/main/java/se/su/dsv/scipro/match/FirstMeeting.java index 2df0e579c7..4367c24d73 100755 --- a/core/src/main/java/se/su/dsv/scipro/match/FirstMeeting.java +++ b/core/src/main/java/se/su/dsv/scipro/match/FirstMeeting.java @@ -1,6 +1,16 @@ package se.su.dsv.scipro.match; -import jakarta.persistence.*; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + import java.io.Serializable; import java.util.Date; import java.util.Objects; @@ -9,72 +19,92 @@ import java.util.Objects; @Table(name = "idea_first_meeting") @Cacheable(true) public class FirstMeeting implements Serializable { - public static final int LENGTH = 1024; + private static final int LENGTH = 1024; + + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Basic(optional = false) - private Date firstMeetingDate; - - @Column(nullable = false, length = LENGTH) - private String room; - - @Column(nullable = true, length = LENGTH) + @Basic + @Column(name = "description", nullable = true, length = LENGTH) private String description; + @Basic(optional = false) + @Column(name = "first_meeting_date") + private Date firstMeetingDate; + + @Basic + @Column(name = "room", nullable = false, length = LENGTH) + private String room; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (idea_first_meeting) referencing other + // tables. + // ---------------------------------------------------------------------------------- @OneToOne(optional = false) + @JoinColumn(name = "idea_id", referencedColumnName = "id") private Idea idea; - public FirstMeeting() { - - } + // ---------------------------------------------------------------------------------- + // constructors + // ---------------------------------------------------------------------------------- + public FirstMeeting() { } public FirstMeeting(Date firstMeetingDate, Idea idea) { this.firstMeetingDate = firstMeetingDate; this.idea = idea; } + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- + public Long getId() { return this.id; } - public Date getFirstMeetingDate() { - return this.firstMeetingDate; - } - - public String getRoom() { - return this.room; - } - - public String getDescription() { - return this.description; - } - - public Idea getIdea() { - return this.idea; - } - public void setId(Long id) { this.id = id; } - public void setFirstMeetingDate(Date firstMeetingDate) { - this.firstMeetingDate = firstMeetingDate; - } - - public void setRoom(String room) { - this.room = room; + public String getDescription() { + return this.description; } public void setDescription(String description) { this.description = description; } + public Date getFirstMeetingDate() { + return this.firstMeetingDate; + } + + public void setFirstMeetingDate(Date firstMeetingDate) { + this.firstMeetingDate = firstMeetingDate; + } + + public String getRoom() { + return this.room; + } + + public void setRoom(String room) { + this.room = room; + } + + public Idea getIdea() { + return this.idea; + } + public void setIdea(Idea idea) { this.idea = idea; } + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -94,11 +124,13 @@ public class FirstMeeting implements Serializable { @Override public int hashCode() { - return Objects.hash(this.getId(), this.getFirstMeetingDate(), this.getRoom(), this.getDescription(), this.getIdea()); + return Objects.hash(this.getId(), this.getFirstMeetingDate(), this.getRoom(), this.getDescription(), + this.getIdea()); } @Override public String toString() { - return "FirstMeeting(id=" + this.getId() + ", firstMeetingDate=" + this.getFirstMeetingDate() + ", room=" + this.getRoom() + ", description=" + this.getDescription() + ", idea=" + this.getIdea() + ")"; + return "FirstMeeting(id=" + this.getId() + ", firstMeetingDate=" + this.getFirstMeetingDate() + ", room=" + + this.getRoom() + ", description=" + this.getDescription() + ", idea=" + this.getIdea() + ")"; } } diff --git a/core/src/main/java/se/su/dsv/scipro/match/Idea.java b/core/src/main/java/se/su/dsv/scipro/match/Idea.java index 15b457b17b..e2772b539b 100755 --- a/core/src/main/java/se/su/dsv/scipro/match/Idea.java +++ b/core/src/main/java/se/su/dsv/scipro/match/Idea.java @@ -1,103 +1,190 @@ package se.su.dsv.scipro.match; import com.querydsl.core.annotations.QueryInit; +import jakarta.persistence.AttributeOverride; +import jakarta.persistence.AttributeOverrides; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Embedded; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.OrderBy; +import jakarta.persistence.PostLoad; +import jakarta.persistence.PostPersist; +import jakarta.persistence.PostUpdate; +import jakarta.persistence.PrePersist; +import jakarta.persistence.PreUpdate; +import jakarta.persistence.Table; + import se.su.dsv.scipro.data.dataobjects.Member; import se.su.dsv.scipro.project.Project; -import se.su.dsv.scipro.system.*; +import se.su.dsv.scipro.system.DomainObject; +import se.su.dsv.scipro.system.Language; +import se.su.dsv.scipro.system.ProjectType; +import se.su.dsv.scipro.system.ResearchArea; +import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.time.LocalDate; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; @Entity @Table(name = "idea") @Cacheable(true) public class Idea extends DomainObject { + private static final int DESCRIPTION_LENGTH = 4000; + private static final int PREREQUISITES_LENGTH = 4000; + private static final int TITLE_LENGTH = 1024; - public static final int DESCRIPTION_LENGTH = 4000; - public static final int PREREQUISITES_LENGTH = 4000; - public static final int TITLE_LENGTH = 1024; + // ---------------------------------------------------------------------------------- + // basic and embedded JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne(optional = false) - private ProjectType projectType; - - @Enumerated(EnumType.STRING) - private Type type; - - @ManyToOne(optional = false) - private User creator; - + @Basic @Column(nullable = true, length = DESCRIPTION_LENGTH) private String description; + @Basic @Column(nullable = true, length = PREREQUISITES_LENGTH) private String prerequisites; - @OneToMany(fetch = FetchType.LAZY, mappedBy = "idea", cascade = CascadeType.ALL, orphanRemoval = true) - @QueryInit({"user", "program"}) - private Set ideaParticipations = new HashSet<>(); - - @ManyToOne(optional = true) - private ApplicationPeriod applicationPeriod; - + @Basic @Column(nullable = false, length = TITLE_LENGTH) private String title; - @ManyToOne(optional = true) - private ResearchArea researchArea; - - @ElementCollection - @CollectionTable(name = "idea_language") - @Column(name = "language") + @Basic @Enumerated(EnumType.STRING) - private Set languages = EnumSet.noneOf(Language.class); + private Type type; + + @Basic + @Column(name = "published") + private boolean published = true; + + @Enumerated(EnumType.STRING) + @Column(name = "cached_status") + private Status cachedStatus; + + @Basic + @Column(name = "inactive") + private boolean inactive = false; @Embedded @AttributeOverrides({ - @AttributeOverride(name = "practicalHow", column = @Column(insertable = false, updatable = false)), - @AttributeOverride(name = "literature", column = @Column(insertable = false, updatable = false)), - @AttributeOverride(name = "theoryHow", column = @Column(insertable = false, updatable = false)), - @AttributeOverride(name = "why", column = @Column(insertable = false, updatable = false)), - @AttributeOverride(name = "what", column = @Column(insertable = false, updatable = false)) + @AttributeOverride(name = "practicalHow", column = @Column(name = "practical_how", insertable = false, updatable = false)), + @AttributeOverride(name = "theoryHow", column = @Column(name = "theory_how", insertable = false, updatable = false)), + @AttributeOverride(name = "what", column = @Column(name = "what", insertable = false, updatable = false)), + @AttributeOverride(name = "why", column = @Column(name = "why", insertable = false, updatable = false)), + @AttributeOverride(name = "literature", column = @Column(name = "literature", insertable = false, updatable = false)) }) private Watson watson; @Embedded + @AttributeOverrides({ + @AttributeOverride(name = "literature", column = @Column(name = "literature", insertable = false, updatable = false)), + @AttributeOverride(name = "background", column = @Column(name = "background", insertable = false, updatable = false)), + @AttributeOverride(name = "problem", column = @Column(name = "problem", insertable = false, updatable = false)), + @AttributeOverride(name = "method", column = @Column(name = "method", insertable = false, updatable = false)), + @AttributeOverride(name = "interests", column = @Column(name = "interests", insertable = false, updatable = false)) + }) private TholanderBox tholanderBox = new TholanderBox(); - @ManyToMany - private Set keywords = new HashSet<>(); + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (idea) referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = true) + @JoinColumn(name = "application_period_id", referencedColumnName = "id") + private ApplicationPeriod applicationPeriod; + + @ManyToOne(optional = false) + @JoinColumn(name = "creator_user_id", referencedColumnName = "id") + private User creator; + + @OneToOne(optional = true, cascade = CascadeType.ALL) + @JoinColumn(name = "latest_match_id", referencedColumnName = "id") + @QueryInit({"supervisor.user", "supervisor.unit"}) + private Match match; @OneToOne + @JoinColumn(name = "project_id", referencedColumnName = "id") private Project project; - @OneToOne(mappedBy = "idea", orphanRemoval = true, optional = true) - private FirstMeeting firstMeeting; + @ManyToOne(optional = false) + @JoinColumn(name = "project_type_id", referencedColumnName = "id") + private ProjectType projectType; + @ManyToOne(optional = true) + @JoinColumn(name = "research_area_id", referencedColumnName = "id") + private ResearchArea researchArea; + + // ---------------------------------------------------------------------------------- + // @ManyToMany JPA-mappings + // ---------------------------------------------------------------------------------- + + // many-to-many from table "keyword" through table "idea_keyword" + @ManyToMany + @JoinTable(name="idea_keyword", + joinColumns = @JoinColumn(name = "idea_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "keyword_id", referencedColumnName = "id")) + private Set keywords = new HashSet<>(); + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "idea" + // ---------------------------------------------------------------------------------- + + // from table idea_language + @ElementCollection + @CollectionTable(name = "idea_language", + joinColumns = @JoinColumn(name = "idea_id", referencedColumnName = "id")) + @Column(name = "language") + @Enumerated(EnumType.STRING) + private Set languages = EnumSet.noneOf(Language.class); + + // from table idea_export + @OneToMany(mappedBy = "idea", cascade = CascadeType.ALL) + private List exports = new ArrayList<>(); + + // from table idea_student + @OneToMany(fetch = FetchType.LAZY, mappedBy = "idea", cascade = CascadeType.ALL, orphanRemoval = true) + @QueryInit({"user", "program"}) + private Set ideaParticipations = new HashSet<>(); + + // from table "idea_match" @OneToMany(fetch = FetchType.LAZY, mappedBy = "idea", cascade = CascadeType.ALL) @OrderBy("dateCreated DESC") private List matchHistory = new ArrayList<>(); - @OneToOne(optional = true, cascade = CascadeType.ALL) - @QueryInit({"supervisor.user", "supervisor.unit"}) - private Match match; - - @Column(name = "published") - private boolean published = true; - - @OneToMany(mappedBy = "idea", cascade = CascadeType.ALL) - private List exports = new ArrayList<>(); - - @Enumerated(EnumType.STRING) - private Status cachedStatus; - - @Basic - private boolean inactive = false; + // from table "idea_first_meeting" + @OneToOne(mappedBy = "idea", orphanRemoval = true, optional = true) + private FirstMeeting firstMeeting; + // ---------------------------------------------------------------------------------- + // methods... + // ---------------------------------------------------------------------------------- public Idea copy(User supervisor) { Idea copy = new Idea(); copy.projectType = this.projectType; @@ -448,7 +535,9 @@ public class Idea extends DomainObject { public String toString() { return "Student idea"; } - }, SUPERVISOR { + }, + + SUPERVISOR { @Override public String toString() { return "Supervisor idea"; @@ -463,18 +552,21 @@ public class Idea extends DomainObject { return "Unmatched"; } }, + MATCHED { @Override public String toString() { return "Matched, no project"; } }, + COMPLETED { @Override public String toString() { return "Matched, has project"; } }, + INACTIVE { @Override public String toString() { diff --git a/core/src/main/java/se/su/dsv/scipro/match/IdeaExport.java b/core/src/main/java/se/su/dsv/scipro/match/IdeaExport.java index 39b00e453a..321ccda22b 100644 --- a/core/src/main/java/se/su/dsv/scipro/match/IdeaExport.java +++ b/core/src/main/java/se/su/dsv/scipro/match/IdeaExport.java @@ -1,8 +1,18 @@ package se.su.dsv.scipro.match; +import jakarta.persistence.Basic; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import se.su.dsv.scipro.system.DomainObject; -import jakarta.persistence.*; import java.util.Objects; @Entity @@ -11,56 +21,69 @@ public class IdeaExport extends DomainObject { public enum Result { FAIL, SUCCESS } + // ---------------------------------------------------------------------------------- + // basic and embedded JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Enumerated(EnumType.STRING) - private Result result; - @Basic private String reason; + @Enumerated(EnumType.STRING) + private Result result; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (idea_export) referencing other tables + // ---------------------------------------------------------------------------------- @ManyToOne(optional = false) + @JoinColumn(name = "idea_id", referencedColumnName = "id") private Idea idea; - public boolean wasSuccessful() { - return result == Result.SUCCESS; - } - + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public Result getResult() { - return this.result; - } - - public String getReason() { - return this.reason; - } - - public Idea getIdea() { - return this.idea; - } - public void setId(Long id) { this.id = id; } - public void setResult(Result result) { - this.result = result; + public String getReason() { + return this.reason; } public void setReason(String reason) { this.reason = reason; } + public Result getResult() { + return this.result; + } + + public void setResult(Result result) { + this.result = result; + } + + public Idea getIdea() { + return this.idea; + } + public void setIdea(Idea idea) { this.idea = idea; } + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- + public boolean wasSuccessful() { + return result == Result.SUCCESS; + } + @Override public boolean equals(final Object o) { if (o == this) return true; diff --git a/core/src/main/java/se/su/dsv/scipro/match/IdeaParticipation.java b/core/src/main/java/se/su/dsv/scipro/match/IdeaParticipation.java index 625e38cf8f..7bf357d62f 100755 --- a/core/src/main/java/se/su/dsv/scipro/match/IdeaParticipation.java +++ b/core/src/main/java/se/su/dsv/scipro/match/IdeaParticipation.java @@ -1,83 +1,114 @@ package se.su.dsv.scipro.match; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.Program; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Date; import java.util.Objects; @Entity @Table(name = "idea_student") -@AssociationOverrides({ - @AssociationOverride(name = "idea", - joinColumns = @JoinColumn(name = "idea_id")) }) public class IdeaParticipation implements Serializable { - protected IdeaParticipation() { - - } - - public IdeaParticipation(User student, Idea idea) { - this.user = student; - this.idea = idea; - } + // ---------------------------------------------------------------------------------- + // basic and embedded JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - private User user; - - @ManyToOne - private Idea idea; - + @Basic + @Column(name = "date_created") private Date dateCreated = new Date(); + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (idea_student) referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne + @JoinColumn(name = "idea_id", referencedColumnName = "id") + private Idea idea; + @ManyToOne(optional = true) + @JoinColumn(name = "program_id", referencedColumnName = "id") private Program program; + @ManyToOne + @JoinColumn(name = "user_id", referencedColumnName = "id") + private User user; + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- + + // JPA/Hibernate works by create a child class of your entity class with all database + // tricks in it, it therefore requires no-arg constructor to be able to instantiate + // a new instance. + // By creating a protected constructor, JPA/Hibernate still works as expected, but it + // declares the intention that parameters need to be provided when new instances are + // created. + protected IdeaParticipation() { } + + public IdeaParticipation(User student, Idea idea) { + this.user = student; + this.idea = idea; + } + + // ---------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------- public Long getId() { return this.id; } - public User getUser() { - return this.user; - } - - public Idea getIdea() { - return this.idea; - } - - public Date getDateCreated() { - return this.dateCreated; - } - - public Program getProgram() { - return this.program; - } - public void setId(Long id) { this.id = id; } - public void setUser(User user) { - this.user = user; - } - - public void setIdea(Idea idea) { - this.idea = idea; + public Date getDateCreated() { + return this.dateCreated; } public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; } + public Idea getIdea() { + return this.idea; + } + + public void setIdea(Idea idea) { + this.idea = idea; + } + + public Program getProgram() { + return this.program; + } + public void setProgram(Program program) { this.program = program; } + public User getUser() { + return this.user; + } + + public void setUser(User user) { + this.user = user; + } + + // ---------------------------------------------------------------------------- + // methods + // ---------------------------------------------------------------------------- @Override public String toString() { return "IdeaParticipation(id=" + this.getId() + ", user=" + this.getUser() + ", idea=" + this.getIdea() + ", dateCreated=" + this.getDateCreated() + ", program=" + this.getProgram() + ")"; diff --git a/core/src/main/java/se/su/dsv/scipro/match/Keyword.java b/core/src/main/java/se/su/dsv/scipro/match/Keyword.java index 320c278981..060efc46b7 100755 --- a/core/src/main/java/se/su/dsv/scipro/match/Keyword.java +++ b/core/src/main/java/se/su/dsv/scipro/match/Keyword.java @@ -1,15 +1,25 @@ package se.su.dsv.scipro.match; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.Table; + import se.su.dsv.scipro.system.LazyDeletableDomainObject; import se.su.dsv.scipro.system.ResearchArea; -import jakarta.persistence.*; - import java.util.HashSet; import java.util.Objects; import java.util.Set; @Entity +@Table(name = "keyword") @Cacheable(true) public class Keyword extends LazyDeletableDomainObject { @@ -19,8 +29,10 @@ public class Keyword extends LazyDeletableDomainObject { private String keyword; - @ManyToMany(fetch = FetchType.EAGER,targetEntity=ResearchArea.class) - @JoinTable(name="Keyword_researcharea") + @ManyToMany(fetch = FetchType.EAGER, targetEntity = ResearchArea.class) + @JoinTable(name="keyword_research_area", + joinColumns = @JoinColumn(name = "keyword_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "research_area_id", referencedColumnName = "id")) private Set researchAreas = new HashSet<>(); public Keyword() { diff --git a/core/src/main/java/se/su/dsv/scipro/match/Match.java b/core/src/main/java/se/su/dsv/scipro/match/Match.java index ec4bb68099..2408e5058f 100755 --- a/core/src/main/java/se/su/dsv/scipro/match/Match.java +++ b/core/src/main/java/se/su/dsv/scipro/match/Match.java @@ -1,56 +1,85 @@ package se.su.dsv.scipro.match; import com.querydsl.core.annotations.QueryInit; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.Objects; @Entity -@Cacheable(true) @Table(name = "idea_match") +@Cacheable(true) public class Match extends DomainObject { + + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne(optional = false) - private Idea idea; - - @ManyToOne - @QueryInit({"unit"}) - private User supervisor; - + @Basic @Enumerated(EnumType.STRING) private Idea.Status status; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (idea_match) referencing other tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional = true) + @JoinColumn(name = "changed_by_user_id", referencedColumnName = "id") private User changedBy; - public User getSupervisor() { - return supervisor; - } + @ManyToOne(optional = false) + @JoinColumn(name = "idea_id", referencedColumnName = "id") + private Idea idea; + @ManyToOne + @JoinColumn(name = "supervisor_user_id", referencedColumnName = "id") + @QueryInit({"unit"}) + private User supervisor; + + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public Idea getIdea() { - return this.idea; + public void setId(Long id) { + this.id = id; } public Idea.Status getStatus() { return this.status; } + public void setStatus(Idea.Status status) { + this.status = status; + } + public User getChangedBy() { return this.changedBy; } - public void setId(Long id) { - this.id = id; + public void setChangedBy(User changedBy) { + this.changedBy = changedBy; + } + + public Idea getIdea() { + return this.idea; } public void setIdea(Idea idea) { @@ -61,14 +90,13 @@ public class Match extends DomainObject { this.supervisor = supervisor; } - public void setStatus(Idea.Status status) { - this.status = status; - } - - public void setChangedBy(User changedBy) { - this.changedBy = changedBy; + public User getSupervisor() { + return supervisor; } + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -93,6 +121,7 @@ public class Match extends DomainObject { @Override public String toString() { - return "Match(id=" + this.getId() + ", supervisor=" + this.getSupervisor() + ", status=" + this.getStatus() + ", changedBy=" + this.getChangedBy() + ")"; + return "Match(id=" + this.getId() + ", supervisor=" + this.getSupervisor() + ", status=" + this.getStatus() + + ", changedBy=" + this.getChangedBy() + ")"; } } diff --git a/core/src/main/java/se/su/dsv/scipro/match/PreliminaryMatch.java b/core/src/main/java/se/su/dsv/scipro/match/PreliminaryMatch.java index 5845f8f479..4a2b0229ba 100644 --- a/core/src/main/java/se/su/dsv/scipro/match/PreliminaryMatch.java +++ b/core/src/main/java/se/su/dsv/scipro/match/PreliminaryMatch.java @@ -1,70 +1,98 @@ package se.su.dsv.scipro.match; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.Objects; @Entity @Table(name = "preliminary_match") public class PreliminaryMatch extends DomainObject { + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic + @Column(name = "comment") + private String comment; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (idea_first_meeting) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne + @JoinColumn(name = "idea_id", referencedColumnName = "id") private Idea idea; @ManyToOne + @JoinColumn(name = "supervisor_user_id", referencedColumnName = "id") private User supervisor; - private String comment; - - // JPA - public PreliminaryMatch() { - } + // ---------------------------------------------------------------------------------- + // constructors + // ---------------------------------------------------------------------------------- + public PreliminaryMatch() { } public PreliminaryMatch(final Idea idea) { this.idea = idea; } + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public Idea getIdea() { - return this.idea; - } - - public User getSupervisor() { - return this.supervisor; - } - - public String getComment() { - return this.comment; - } - public void setId(Long id) { this.id = id; } - public void setIdea(Idea idea) { - this.idea = idea; - } - - public void setSupervisor(User supervisor) { - this.supervisor = supervisor; + public String getComment() { + return this.comment; } public void setComment(String comment) { this.comment = comment; } + public Idea getIdea() { + return this.idea; + } + + public void setIdea(Idea idea) { + this.idea = idea; + } + + public User getSupervisor() { + return this.supervisor; + } + + public void setSupervisor(User supervisor) { + this.supervisor = supervisor; + } + + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- @Override public String toString() { - return "PreliminaryMatch(id=" + this.getId() + ", idea=" + this.getIdea() + ", supervisor=" + this.getSupervisor() + ", comment=" + this.getComment() + ")"; + return "PreliminaryMatch(id=" + this.getId() + ", idea=" + this.getIdea() + ", supervisor=" + + this.getSupervisor() + ", comment=" + this.getComment() + ")"; } @Override diff --git a/core/src/main/java/se/su/dsv/scipro/match/Target.java b/core/src/main/java/se/su/dsv/scipro/match/Target.java index 2be7fac981..79d88f4514 100644 --- a/core/src/main/java/se/su/dsv/scipro/match/Target.java +++ b/core/src/main/java/se/su/dsv/scipro/match/Target.java @@ -20,12 +20,12 @@ public class Target implements Serializable { @MapsId("applicationPeriodId") @ManyToOne - @JoinColumn(name = "applicationPeriodId") + @JoinColumn(name = "application_period_id") private ApplicationPeriod applicationPeriod; @MapsId("projectTypeId") @ManyToOne - @JoinColumn(name = "projectTypeId") + @JoinColumn(name = "project_type_id") private ProjectType projectType; private int target; diff --git a/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/Milestone.java b/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/Milestone.java index 45bbd74bfb..f72cf1954f 100644 --- a/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/Milestone.java +++ b/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/Milestone.java @@ -1,39 +1,54 @@ package se.su.dsv.scipro.milestones.dataobjects; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.data.dataobjects.Member; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.Collections; import java.util.List; @Entity @Table(name = "milestone") public class Milestone extends DomainObject { - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) protected long id; - @ManyToOne - private Project project; - - @ManyToOne(optional = true) - private User user; - - @ManyToOne(optional = false) - private MilestoneActivityTemplate activity; - + @Basic @Column(name = "confirmed", nullable = false) private boolean confirmed = false; - @Override - public Long getId() { - return id; - } + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (milestone) referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + @JoinColumn(name = "milestone_activity_template_id", referencedColumnName = "id") + private MilestoneActivityTemplate activity; + @ManyToOne + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + + @ManyToOne(optional = true) + @JoinColumn(name = "user_id", referencedColumnName = "id") + private User user; + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected Milestone() { } @@ -49,6 +64,15 @@ public class Milestone extends DomainObject { this.activity = activity; } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + + @Override + public Long getId() { + return id; + } + public void setId(Long id) { this.id = id; } @@ -61,14 +85,6 @@ public class Milestone extends DomainObject { this.confirmed = confirmed; } - public Project getProject() { - return project; - } - - public void setProject(Project project) { - this.project = project; - } - public MilestoneActivityTemplate getActivity() { return activity; } @@ -77,11 +93,22 @@ public class Milestone extends DomainObject { this.activity = activity; } - public List getMembers() { - return Collections.singletonList(new Member(user, Member.Type.MILESTONE_INDIVIDUAL)); + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; } public User getUser() { return this.user; } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + public List getMembers() { + return Collections.singletonList(new Member(user, Member.Type.MILESTONE_INDIVIDUAL)); + } } diff --git a/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/MilestoneActivityTemplate.java b/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/MilestoneActivityTemplate.java index f86421e861..583c558278 100644 --- a/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/MilestoneActivityTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/MilestoneActivityTemplate.java @@ -1,10 +1,23 @@ package se.su.dsv.scipro.milestones.dataobjects; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.Event; import se.su.dsv.scipro.system.LazyDeletableDomainObject; import se.su.dsv.scipro.system.ProjectType; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Comparator; import java.util.HashSet; @@ -18,42 +31,66 @@ public class MilestoneActivityTemplate extends LazyDeletableDomainObject { public static final String PEER_REVIEW_ONE = "PEER_REVIEW_ONE"; public static final String PEER_REVIEW_TWO = "PEER_REVIEW_TWO"; + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Basic(optional = false) + @Column(name = "title") private String title; @Basic(optional = true) + @Column(name = "description") private String description; @Enumerated(EnumType.STRING) + @Column(name = "type") private Type type; - @Column(unique = true) + @Basic + @Column(name = "code", unique = true) private String code; + @Basic + @Column(name = "sort_order") + private int sortOrder; + + @Basic + @Column(name = "editable_by_students") + private boolean editableByStudents = false; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (milestone_activity_template) + // referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne + @JoinColumn(name = "milestone_phase_template_id", referencedColumnName = "id", nullable = false) + private MilestonePhaseTemplate milestonePhaseTemplate; + + @OneToOne + @JoinColumn(name = "activated_by_event_name", referencedColumnName = "name") + private Event activatedBy; + + // ---------------------------------------------------------------------------------- + // @ManyToMany JPA-mappings + // ---------------------------------------------------------------------------------- + + // Many-to-Many between table milestone_activity_template and project_type through + // table "milestone_activity_template_project_type". @ManyToMany @JoinTable( - joinColumns = @JoinColumn(name = "milestone_activity_template_id") + name = "milestone_activity_template_project_type", + joinColumns = @JoinColumn(name = "milestone_activity_template_id"), + inverseJoinColumns = @JoinColumn(name = "project_type_id") ) private Set projectTypes = new HashSet<>(); - @ManyToOne - @JoinColumn(name = "phase", nullable = false) - private MilestonePhaseTemplate milestonePhaseTemplate; - - @Column - private int sortOrder; - - @Column - private boolean editableByStudents = false; - - @OneToOne - @JoinColumn(name = "activatedBy") - private Event activatedBy; - + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- public MilestoneActivityTemplate() { } @@ -67,10 +104,9 @@ public class MilestoneActivityTemplate extends LazyDeletableDomainObject { this.description = description; } - public void addProjectType(ProjectType projectType) { - projectTypes.add(projectType); - } - + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; @@ -80,79 +116,95 @@ public class MilestoneActivityTemplate extends LazyDeletableDomainObject { return this.title; } - public String getDescription() { - return this.description; - } - - public Type getType() { - return this.type; - } - - public String getCode() { - return this.code; - } - - public Set getProjectTypes() { - return this.projectTypes; - } - - public MilestonePhaseTemplate getMilestonePhaseTemplate() { - return this.milestonePhaseTemplate; - } - - public int getSortOrder() { - return this.sortOrder; - } - - public boolean isEditableByStudents() { - return this.editableByStudents; - } - - public Event getActivatedBy() { - return this.activatedBy; - } - public void setTitle(String title) { this.title = title; } + public String getDescription() { + return this.description; + } + public void setDescription(String description) { this.description = description; } + public Type getType() { + return this.type; + } + public void setType(Type type) { this.type = type; } + public String getCode() { + return this.code; + } + public void setCode(String code) { this.code = code; } - public void setMilestonePhaseTemplate(MilestonePhaseTemplate milestonePhaseTemplate) { - this.milestonePhaseTemplate = milestonePhaseTemplate; + public int getSortOrder() { + return this.sortOrder; } public void setSortOrder(int sortOrder) { this.sortOrder = sortOrder; } + public boolean isEditableByStudents() { + return this.editableByStudents; + } + public void setEditableByStudents(boolean editableByStudents) { this.editableByStudents = editableByStudents; } + public MilestonePhaseTemplate getMilestonePhaseTemplate() { + return this.milestonePhaseTemplate; + } + + public void setMilestonePhaseTemplate(MilestonePhaseTemplate milestonePhaseTemplate) { + this.milestonePhaseTemplate = milestonePhaseTemplate; + } + + public Event getActivatedBy() { + return this.activatedBy; + } + public void setActivatedBy(Event activatedBy) { this.activatedBy = activatedBy; } + public Set getProjectTypes() { + return this.projectTypes; + } + public void setProjectTypes(Set projectTypes) { this.projectTypes = projectTypes; } - public static class BySortOrderComparator implements Comparator, Serializable { + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + public void addProjectType(ProjectType projectType) { + projectTypes.add(projectType); + } + + public boolean isAutomatic() { + return code != null || activatedBy != null; + } + + // ---------------------------------------------------------------------------------- + // Nested classes and types + // ---------------------------------------------------------------------------------- + public static class BySortOrderComparator implements Comparator, + Serializable { @Override public int compare(MilestoneActivityTemplate o1, MilestoneActivityTemplate o2) { int sortOrderResult = o1.sortOrder - o2.sortOrder; - int phaseSortOrderResult = o1.milestonePhaseTemplate.getSortOrder() - o2.getMilestonePhaseTemplate().getSortOrder(); + int phaseSortOrderResult = o1.milestonePhaseTemplate.getSortOrder() - + o2.getMilestonePhaseTemplate().getSortOrder(); if (phaseSortOrderResult == 0) { return sortOrderResult; @@ -175,8 +227,4 @@ public class MilestoneActivityTemplate extends LazyDeletableDomainObject { return asString; } } - - public boolean isAutomatic() { - return code != null || activatedBy != null; - } } diff --git a/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/MilestonePhaseTemplate.java b/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/MilestonePhaseTemplate.java index 3078dd4d24..34b29d2fe4 100644 --- a/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/MilestonePhaseTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/milestones/dataobjects/MilestonePhaseTemplate.java @@ -1,31 +1,41 @@ package se.su.dsv.scipro.milestones.dataobjects; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.LazyDeletableDomainObject; -import jakarta.persistence.*; import java.util.Objects; @Entity @Table(name = "milestone_phase_template") public class MilestonePhaseTemplate extends LazyDeletableDomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) protected long id; - @Override - public Long getId() { - return id; - } - @Basic(optional = false) + @Column(name = "title") private String title; @Basic(optional = true) + @Column(name = "description") private String description; - @Column(name = "sortOrder") + @Basic + @Column(name = "sort_order") private int sortOrder; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- public MilestonePhaseTemplate() { } @@ -41,37 +51,47 @@ public class MilestonePhaseTemplate extends LazyDeletableDomainObject { this.sortOrder = sortOrder; } - public String getTitle() { - return this.title; - } - - public String getDescription() { - return this.description; - } - - public int getSortOrder() { - return this.sortOrder; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return id; } public void setId(long id) { this.id = id; } + public String getTitle() { + return this.title; + } + public void setTitle(String title) { this.title = title; } + public String getDescription() { + return this.description; + } + public void setDescription(String description) { this.description = description; } + public int getSortOrder() { + return this.sortOrder; + } + public void setSortOrder(int sortOrder) { this.sortOrder = sortOrder; } - @Override - public String toString() { - return "MilestonePhaseTemplate(id=" + this.getId() + ", title=" + this.getTitle() + ", description=" + this.getDescription() + ", sortOrder=" + this.getSortOrder() + ")"; + // ---------------------------------------------------------------------------------- + // Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof MilestonePhaseTemplate; } @Override @@ -86,12 +106,13 @@ public class MilestonePhaseTemplate extends LazyDeletableDomainObject { && this.getSortOrder() == other.getSortOrder(); } - protected boolean canEqual(final Object other) { - return other instanceof MilestonePhaseTemplate; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getTitle(), this.getDescription(), this.getSortOrder()); } + + @Override + public String toString() { + return "MilestonePhaseTemplate(id=" + this.getId() + ", title=" + this.getTitle() + ", description=" + this.getDescription() + ", sortOrder=" + this.getSortOrder() + ")"; + } } diff --git a/core/src/main/java/se/su/dsv/scipro/milestones/service/MilestoneActivator.java b/core/src/main/java/se/su/dsv/scipro/milestones/service/MilestoneActivator.java index d19f65687a..e70062e7b1 100644 --- a/core/src/main/java/se/su/dsv/scipro/milestones/service/MilestoneActivator.java +++ b/core/src/main/java/se/su/dsv/scipro/milestones/service/MilestoneActivator.java @@ -61,7 +61,7 @@ public class MilestoneActivator { int minimumActiveParticipationsToBeGraded = event.getProject() .getProjectType() .getProjectTypeSettings() - .getMinimumActiveParticipationsToBeGraded(); + .getMinActiveParticipationsToBeGraded(); if (completedParticipations >= minimumActiveParticipationsToBeGraded) { activateIndividualMilestone(Set.of("ParticipationGradingEvent"), event.getProject(), event.getStudent()); } else { diff --git a/core/src/main/java/se/su/dsv/scipro/nonworkperiod/NonWorkDayPeriod.java b/core/src/main/java/se/su/dsv/scipro/nonworkperiod/NonWorkDayPeriod.java index b12335ead6..639da2f1f5 100755 --- a/core/src/main/java/se/su/dsv/scipro/nonworkperiod/NonWorkDayPeriod.java +++ b/core/src/main/java/se/su/dsv/scipro/nonworkperiod/NonWorkDayPeriod.java @@ -1,24 +1,29 @@ package se.su.dsv.scipro.nonworkperiod; -import jakarta.persistence.GenerationType; -import se.su.dsv.scipro.system.DomainObject; - import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Table; +import se.su.dsv.scipro.system.DomainObject; + import java.time.LocalDate; import java.util.Objects; @Entity @Cacheable(true) +@Table(name = "non_work_day_period") public class NonWorkDayPeriod extends DomainObject { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "start_date") private LocalDate startDate; + @Column(name = "end_date") private LocalDate endDate; private String comment; diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/CustomEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/CustomEvent.java index 3fd7e4a0ac..f738fbf6c8 100644 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/CustomEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/CustomEvent.java @@ -1,5 +1,7 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; import se.su.dsv.scipro.system.DomainObject; import jakarta.persistence.Entity; @@ -13,6 +15,8 @@ public class CustomEvent extends NotificationEvent { IDEA_DELETED } + @Basic + @Column(name = "event") @Enumerated(EnumType.STRING) private CustomEvent.Event event; diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/GroupEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/GroupEvent.java index fa25851094..079c0cb09a 100644 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/GroupEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/GroupEvent.java @@ -1,5 +1,8 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.group.Group; import se.su.dsv.scipro.system.DomainObject; @@ -11,37 +14,40 @@ import jakarta.persistence.ManyToOne; @Entity public class GroupEvent extends NotificationEvent { - public void setEvent(Event event) { - this.event = event; - } - public enum Event { MESSAGE_THREAD_CREATED, MESSAGE_THREAD_REPLY } + @Basic + @Column(name = "event") + @Enumerated(EnumType.STRING) + private Event event; + + @ManyToOne + @JoinColumn(name = "project_group_id", referencedColumnName = "id") + private Group group; + + public GroupEvent() { + super(Notification.Type.GROUP); + } + + @Override + public Enum getEvent() { + return event; + } + + public void setEvent(Event event) { + this.event = event; + } + public Group getGroup() { return group; } - @ManyToOne - private Group group; - - @Enumerated(EnumType.STRING) - private Event event; - - public GroupEvent() { - super(Notification.Type.GROUP); - } - public void setGroup(Group group) { this.group = group; } - @Override - public Enum getEvent() { - return event; - } - @Override protected String getEntityTitle() { return group.getTitle(); diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/IdeaEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/IdeaEvent.java index 8ef2b2d070..54df3b315e 100755 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/IdeaEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/IdeaEvent.java @@ -1,5 +1,8 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.match.Idea; import se.su.dsv.scipro.system.DomainObject; @@ -11,18 +14,29 @@ import jakarta.persistence.ManyToOne; @Entity public class IdeaEvent extends NotificationEvent { - public enum Event { STATUS_CHANGE, PARTNER_ACCEPT, ADDED_AS_PARTNER, FIRST_MEETING, REMOVED_AS_PARTNER, EXPORTED_FAIL } - @ManyToOne - private Idea idea; - + @Basic + @Column(name = "event") @Enumerated(EnumType.STRING) private Event event; + @ManyToOne + @JoinColumn(name = "idea_id", referencedColumnName = "id") + private Idea idea; + + @Override + public Event getEvent() { + return event; + } + + public void setEvent(Event event) { + this.event = event; + } + public IdeaEvent() { super(Notification.Type.IDEA); } @@ -35,15 +49,6 @@ public class IdeaEvent extends NotificationEvent { this.idea = idea; } - @Override - public Event getEvent() { - return event; - } - - public void setEvent(Event event) { - this.event = event; - } - @Override public String getEntityTitle() { return idea.getTitle(); diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/MileStoneEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/MileStoneEvent.java index 9e4c1bf5a9..f84a47be57 100644 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/MileStoneEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/MileStoneEvent.java @@ -1,5 +1,8 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.milestones.dataobjects.Milestone; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; @@ -17,24 +20,64 @@ public class MileStoneEvent extends NotificationEvent { MILESTONE_CONFIRMED, MILESTONE_REVOKED } - @ManyToOne - private Milestone milestone; - + @Basic + @Column(name = "event") @Enumerated(EnumType.STRING) private Event event; + @ManyToOne + @JoinColumn(name = "milestone_id", referencedColumnName = "id") + private Milestone milestone; + public MileStoneEvent() { super(Notification.Type.MILESTONE); } @Override - public Project getProject() { - return milestone.getProject(); + public Enum getEvent() { + return event; + } + + public void setEvent(Event event) { + this.event = event; + } + + public Milestone getMilestone() { + return this.milestone; + } + + public void setMilestone(Milestone milestone) { + this.milestone = milestone; } @Override - public Enum getEvent() { - return event; + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof MileStoneEvent)) return false; + final MileStoneEvent other = (MileStoneEvent) o; + return other.canEqual(this) + && super.equals(o) + && Objects.equals(this.getMilestone(), other.getMilestone()) + && Objects.equals(this.getEvent(), other.getEvent()); + } + + @Override + public int hashCode() { + return Objects.hash(this.getMilestone(), this.getEvent()); + } + + @Override + public String toString() { + return "MileStoneEvent(milestone=" + this.getMilestone() + ", event=" + this.getEvent() + ")"; + } + + protected boolean canEqual(final Object other) { + return other instanceof MileStoneEvent; + } + + @Override + public Project getProject() { + return milestone.getProject(); } @Override @@ -51,41 +94,4 @@ public class MileStoneEvent extends NotificationEvent { public DomainObject getEntity() { return milestone; } - - public Milestone getMilestone() { - return this.milestone; - } - - public void setMilestone(Milestone milestone) { - this.milestone = milestone; - } - - public void setEvent(Event event) { - this.event = event; - } - - @Override - public String toString() { - return "MileStoneEvent(milestone=" + this.getMilestone() + ", event=" + this.getEvent() + ")"; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof MileStoneEvent)) return false; - final MileStoneEvent other = (MileStoneEvent) o; - return other.canEqual(this) - && super.equals(o) - && Objects.equals(this.getMilestone(), other.getMilestone()) - && Objects.equals(this.getEvent(), other.getEvent()); - } - - protected boolean canEqual(final Object other) { - return other instanceof MileStoneEvent; - } - - @Override - public int hashCode() { - return Objects.hash(this.getMilestone(), this.getEvent()); - } } diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/Notification.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/Notification.java index 073be08b40..5102db88cd 100755 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/Notification.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/Notification.java @@ -1,41 +1,59 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; - @Entity +@Table(name = "notification") public class Notification extends DomainObject { - - public enum Type { - PROJECT, IDEA, FINAL_SEMINAR, PEER, MILESTONE, - GROUP, FORUM, CUSTOM - } - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Basic(optional = false) - private boolean unread = true; - - @Basic(optional = false) + @Column(name = "mailed") private boolean mailed = false; + @Basic(optional = false) + @Column(name = "unread") + private boolean unread = true; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (notification) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "notificationData_id") + @JoinColumn(name = "notification_data_id", referencedColumnName = "id") private NotificationEvent notificationEvent; @ManyToOne + @JoinColumn(name = "user_id", referencedColumnName = "id") private User user; + // ---------------------------------------------------------------------------------- + // Constructor + // ---------------------------------------------------------------------------------- public Notification() { - } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return id; @@ -45,6 +63,14 @@ public class Notification extends DomainObject { this.id = id; } + public boolean isMailed() { + return mailed; + } + + public void setMailed(boolean mailed) { + this.mailed = mailed; + } + public boolean isUnread() { return unread; } @@ -69,14 +95,9 @@ public class Notification extends DomainObject { this.user = user; } - public boolean isMailed() { - return mailed; - } - - public void setMailed(boolean mailed) { - this.mailed = mailed; - } - + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- public String getTitle() { return getNotificationEvent().getTitle(); } @@ -108,4 +129,12 @@ public class Notification extends DomainObject { public User getCausedBy() { return getNotificationEvent().getCausedBy(); } + + // ---------------------------------------------------------------------------------- + // Nested type + // ---------------------------------------------------------------------------------- + public enum Type { + PROJECT, IDEA, FINAL_SEMINAR, PEER, MILESTONE, + GROUP, FORUM, CUSTOM + } } diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/NotificationEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/NotificationEvent.java index 1aac89eca6..6eb2f15ef4 100755 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/NotificationEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/NotificationEvent.java @@ -1,55 +1,70 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.DiscriminatorColumn; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.Collection; @Entity +@Table(name = "notification_data") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@Table(name = "NotificationData") +@DiscriminatorColumn(name = "subclass") public abstract class NotificationEvent extends DomainObject { - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) protected long id; + @Basic + @Column(name = "type") @Enumerated(EnumType.STRING) protected Notification.Type type; - @OneToMany(mappedBy = "notificationEvent", cascade = CascadeType.ALL, orphanRemoval = true) - private Collection notifications; - @Basic(optional = true) + @Column(name = "source") private String source; @Basic(optional = true) + @Column(name = "additional_source") private String additionalSource; - + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (notification_data) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional = true) + @JoinColumn(name = "caused_by_user_id", referencedColumnName = "id") private User causedBy; - public abstract Enum getEvent(); - - /** - * The title of the entity this event is about. - * - * @return a human readable title - */ - protected abstract String getEntityTitle(); - - /** - * Return true if there is an entity backing this event. - * Used to determine if this event was about a deletion, or has since been deleted. - */ - public abstract boolean hasEntity(); - - public abstract DomainObject getEntity(); + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "notification_data" + // ---------------------------------------------------------------------------------- + @OneToMany(mappedBy = "notificationEvent", cascade = CascadeType.ALL, orphanRemoval = true) + private Collection notifications; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected NotificationEvent() { } @@ -58,6 +73,9 @@ public abstract class NotificationEvent extends DomainObject { this.type = type; } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return id; @@ -75,14 +93,6 @@ public abstract class NotificationEvent extends DomainObject { this.type = type; } - public Collection getNotifications() { - return notifications; - } - - public void setNotifications(Collection notifications) { - this.notifications = notifications; - } - public String getSource() { return source; } @@ -91,8 +101,12 @@ public abstract class NotificationEvent extends DomainObject { this.source = source; } - public String getTitle() { - return hasEntity() ? getEntityTitle() : "[Deleted entity]"; + public String getAdditionalSource() { + return additionalSource; + } + + public void setAdditionalSource(String additionalSource) { + this.additionalSource = additionalSource; } public User getCausedBy() { @@ -103,6 +117,41 @@ public abstract class NotificationEvent extends DomainObject { this.causedBy = user; } + public Collection getNotifications() { + return notifications; + } + + public void setNotifications(Collection notifications) { + this.notifications = notifications; + } + + // ---------------------------------------------------------------------------------- + // Abstract methods to be implemented by subclasses + // ---------------------------------------------------------------------------------- + /** + * The title of the entity this event is about. + * + * @return a human readable title + */ + protected abstract String getEntityTitle(); + + /** + * Return true if there is an entity backing this event. + * Used to determine if this event was about a deletion, or has since been deleted. + */ + public abstract boolean hasEntity(); + + public abstract DomainObject getEntity(); + + public abstract Enum getEvent(); + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + public String getTitle() { + return hasEntity() ? getEntityTitle() : "[Deleted entity]"; + } + /** * Override this method if the event has an association with a {@link Project}. * @@ -111,12 +160,4 @@ public abstract class NotificationEvent extends DomainObject { public Project getProject() { return null; } - - public String getAdditionalSource() { - return additionalSource; - } - - public void setAdditionalSource(String additionalSource) { - this.additionalSource = additionalSource; - } } diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/PeerEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/PeerEvent.java index 17272c9768..8ca7f15e9e 100755 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/PeerEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/PeerEvent.java @@ -1,5 +1,8 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.peer.PeerReview; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; @@ -12,22 +15,31 @@ import jakarta.persistence.ManyToOne; @Entity public class PeerEvent extends NotificationEvent { - public enum Event { REVIEW_COMPLETED, REVIEW_COMMENT, REVIEW_ACCEPTED, REQUEST_DELETED, - REQUEST_EXPIRED } - - @ManyToOne - private PeerReview review; + public enum Event { + REVIEW_COMPLETED, REVIEW_COMMENT, REVIEW_ACCEPTED, REQUEST_DELETED, + REQUEST_EXPIRED + } + @Basic + @Column(name = "event") @Enumerated(EnumType.STRING) private Event event; + @ManyToOne + @JoinColumn(name = "peer_review_id", referencedColumnName = "id") + private PeerReview review; + public PeerEvent() { super(Notification.Type.PEER); } @Override - public Project getProject() { - return review.getProject(); + public Event getEvent() { + return event; + } + + public void setEvent(Event event) { + this.event = event; } public PeerReview getReview() { @@ -39,12 +51,8 @@ public class PeerEvent extends NotificationEvent { } @Override - public Event getEvent() { - return event; - } - - public void setEvent(Event event) { - this.event = event; + public Project getProject() { + return review.getProject(); } @Override diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/PeerRequestEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/PeerRequestEvent.java index 37355d4d44..72f6dac062 100644 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/PeerRequestEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/PeerRequestEvent.java @@ -1,5 +1,8 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.peer.PeerRequest; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; @@ -12,10 +15,13 @@ import jakarta.persistence.ManyToOne; @Entity public class PeerRequestEvent extends NotificationEvent { + @Basic + @Column(name = "event") @Enumerated(EnumType.STRING) private PeerEvent.Event event; @ManyToOne + @JoinColumn(name = "peer_request_id", referencedColumnName = "id") private PeerRequest request; public PeerRequestEvent() { diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/ProjectEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/ProjectEvent.java index c8c3e51032..a44a3760be 100755 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/ProjectEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/ProjectEvent.java @@ -1,5 +1,8 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; @@ -19,29 +22,23 @@ public class ProjectEvent extends NotificationEvent { FINAL_SEMINAR_APPROVAL_APPROVED, FINAL_SEMINAR_APPROVAL_REJECTED, ROUGH_DRAFT_APPROVAL_REQUESTED, ROUGH_DRAFT_APPROVAL_APPROVED, ROUGH_DRAFT_APPROVAL_REJECTED, REVIEWER_GRADING_REPORT_SUBMITTED, ONE_YEAR_PASSED_FROM_LATEST_ANNUAL_REVIEW, SUPERVISOR_GRADING_INITIAL_ASSESSMENT_DONE, - EXPORTED_SUCCESS, REVIEWER_GRADING_INITIAL_ASSESSMENT_DONE, FIRST_MEETING, OPPOSITION_FAILED, PARTICIPATION_APPROVED, COMPLETED, - PARTICIPATION_FAILED + EXPORTED_SUCCESS, REVIEWER_GRADING_INITIAL_ASSESSMENT_DONE, FIRST_MEETING, OPPOSITION_FAILED, + PARTICIPATION_APPROVED, COMPLETED, PARTICIPATION_FAILED } - @ManyToOne - private Project project; - + @Basic + @Column(name = "event") @Enumerated(EnumType.STRING) private Event event; + @ManyToOne + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + public ProjectEvent() { super(Notification.Type.PROJECT); } - @Override - public Project getProject() { - return project; - } - - public void setProject(Project project) { - this.project = project; - } - @Override public Event getEvent() { return event; @@ -51,6 +48,15 @@ public class ProjectEvent extends NotificationEvent { this.event = event; } + @Override + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + @Override public String getEntityTitle() { return project.getTitle(); diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/ProjectForumEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/ProjectForumEvent.java index a5b2989c19..c95ec8bf05 100644 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/ProjectForumEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/ProjectForumEvent.java @@ -1,5 +1,8 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; @@ -10,29 +13,24 @@ import jakarta.persistence.ManyToOne; @Entity public class ProjectForumEvent extends NotificationEvent { - @ManyToOne - private Project project; - - @Enumerated(EnumType.STRING) - private Event event; - - public void setProject(Project project) { - this.project = project; - } public enum Event { NEW_FORUM_POST, NEW_FORUM_POST_COMMENT, NEW_REVIEWER_INTERACTION } + @Basic + @Column(name = "event") + @Enumerated(EnumType.STRING) + private Event event; + + @ManyToOne + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + public ProjectForumEvent() { super(Notification.Type.FORUM); } - @Override - public Project getProject() { - return this.project; - } - @Override public Event getEvent() { return event; @@ -42,6 +40,15 @@ public class ProjectForumEvent extends NotificationEvent { this.event = event; } + @Override + public Project getProject() { + return this.project; + } + + public void setProject(Project project) { + this.project = project; + } + @Override protected String getEntityTitle() { return project.getTitle(); @@ -56,5 +63,4 @@ public class ProjectForumEvent extends NotificationEvent { public DomainObject getEntity() { return project; } - } diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/SeminarEvent.java b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/SeminarEvent.java index 46951edcc3..dedad4ca0a 100755 --- a/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/SeminarEvent.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/dataobject/SeminarEvent.java @@ -1,5 +1,8 @@ package se.su.dsv.scipro.notifications.dataobject; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.JoinColumn; import se.su.dsv.scipro.finalseminar.FinalSeminar; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; @@ -12,27 +15,24 @@ import jakarta.persistence.ManyToOne; @Entity public class SeminarEvent extends NotificationEvent { - public enum Event { CREATED, ROOM_CHANGED, DATE_CHANGED, OPPOSITION_CHANGED, PARTICIPATION_CHANGED, THESIS_UPLOADED, THESIS_UPLOADED_OPPONENT, - OPPOSITION_REPORT_UPLOADED, THESIS_DELETED, THESIS_UPLOAD_REMIND, CANCELLED} - - @ManyToOne - private FinalSeminar seminar; + public enum Event { CREATED, ROOM_CHANGED, DATE_CHANGED, OPPOSITION_CHANGED, + PARTICIPATION_CHANGED, THESIS_UPLOADED, THESIS_UPLOADED_OPPONENT, + OPPOSITION_REPORT_UPLOADED, THESIS_DELETED, THESIS_UPLOAD_REMIND, CANCELLED + } + @Basic + @Column(name = "event") @Enumerated(EnumType.STRING) private Event event; + @ManyToOne + @JoinColumn(name = "final_seminar_id", referencedColumnName = "id") + private FinalSeminar seminar; + public SeminarEvent() { super(Notification.Type.FINAL_SEMINAR); } - public FinalSeminar getSeminar() { - return seminar; - } - - public void setSeminar(FinalSeminar seminar) { - this.seminar = seminar; - } - @Override public Event getEvent() { return event; @@ -42,6 +42,14 @@ public class SeminarEvent extends NotificationEvent { this.event = event; } + public FinalSeminar getSeminar() { + return seminar; + } + + public void setSeminar(FinalSeminar seminar) { + this.seminar = seminar; + } + @Override public String getEntityTitle() { return seminar.getProject().getTitle(); diff --git a/core/src/main/java/se/su/dsv/scipro/notifications/settings/entities/DeliveryConfiguration.java b/core/src/main/java/se/su/dsv/scipro/notifications/settings/entities/DeliveryConfiguration.java index 65af5aaa5c..7e20fa7ffb 100644 --- a/core/src/main/java/se/su/dsv/scipro/notifications/settings/entities/DeliveryConfiguration.java +++ b/core/src/main/java/se/su/dsv/scipro/notifications/settings/entities/DeliveryConfiguration.java @@ -1,14 +1,21 @@ package se.su.dsv.scipro.notifications.settings.entities; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; + import se.su.dsv.scipro.notifications.dataobject.Notification; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; - @Entity @Table(name = "notification_delivery_configuration", uniqueConstraints = { - @UniqueConstraint(name = "one_setting_per_user", columnNames = {"type", "event", "method", "user_id"}) + @UniqueConstraint(name = "uk_one_setting_per_user", columnNames = {"type", "event", "method", "user_id"}) }) public class DeliveryConfiguration extends Configuration { diff --git a/core/src/main/java/se/su/dsv/scipro/peer/Answer.java b/core/src/main/java/se/su/dsv/scipro/peer/Answer.java index fd7b4b0ca4..bf40f7d72e 100755 --- a/core/src/main/java/se/su/dsv/scipro/peer/Answer.java +++ b/core/src/main/java/se/su/dsv/scipro/peer/Answer.java @@ -1,80 +1,115 @@ package se.su.dsv.scipro.peer; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.checklist.ChecklistAnswerEnum; import se.su.dsv.scipro.system.DomainObject; -import jakarta.persistence.*; import java.util.Objects; @Entity @Table(name="answer") @Cacheable(true) public class Answer extends DomainObject { + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - + + @Basic(optional = false) + @Column(name = "question") + private String question; + + @Enumerated(EnumType.STRING) + @Column(name = "answer", nullable=false) + private ChecklistAnswerEnum answer = ChecklistAnswerEnum.NO_ANSWER; + + @Basic(optional=true) + @Lob + @Column(name = "motivation") + private String motivation; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (answer) referencing other tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional=false) + @JoinColumn(name = "peer_review_id", referencedColumnName = "id") private PeerReview peerReview; - @Basic(optional = false) - private String question; - - @Lob - @Basic(optional=true) - private String motivation; - - @Enumerated(EnumType.STRING) - @Column(nullable=false) - private ChecklistAnswerEnum answer = ChecklistAnswerEnum.NO_ANSWER; - + // ---------------------------------------------------------------------------------- + // constructors + // ---------------------------------------------------------------------------------- public Answer() {} + public Answer(PeerReview peerReview, String question){ this.peerReview = peerReview; this.question = question; } + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public PeerReview getPeerReview() { - return this.peerReview; - } - - public String getQuestion() { - return this.question; - } - - public String getMotivation() { - return this.motivation; - } - - public ChecklistAnswerEnum getAnswer() { - return this.answer; - } - public void setId(Long id) { this.id = id; } - public void setPeerReview(PeerReview peerReview) { - this.peerReview = peerReview; + public String getQuestion() { + return this.question; } public void setQuestion(String question) { this.question = question; } - public void setMotivation(String motivation) { - this.motivation = motivation; + public ChecklistAnswerEnum getAnswer() { + return this.answer; } public void setAnswer(ChecklistAnswerEnum answer) { this.answer = answer; } + public String getMotivation() { + return this.motivation; + } + + public void setMotivation(String motivation) { + this.motivation = motivation; + } + + public PeerReview getPeerReview() { + return this.peerReview; + } + + public void setPeerReview(PeerReview peerReview) { + this.peerReview = peerReview; + } + + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof Answer; + } + @Override public boolean equals(final Object o) { if (o == this) return true; @@ -84,10 +119,6 @@ public class Answer extends DomainObject { && Objects.equals(this.getId(), other.getId()); } - protected boolean canEqual(final Object other) { - return other instanceof Answer; - } - @Override public int hashCode() { return Objects.hashCode(this.getId()); @@ -95,6 +126,7 @@ public class Answer extends DomainObject { @Override public String toString() { - return "Answer(id=" + this.getId() + ", question=" + this.getQuestion() + ", motivation=" + this.getMotivation() + ", answer=" + this.getAnswer() + ")"; + return "Answer(id=" + this.getId() + ", question=" + this.getQuestion() + ", motivation=" + + this.getMotivation() + ", answer=" + this.getAnswer() + ")"; } } diff --git a/core/src/main/java/se/su/dsv/scipro/peer/Comment.java b/core/src/main/java/se/su/dsv/scipro/peer/Comment.java index 32d3fe771d..bb5c68db96 100755 --- a/core/src/main/java/se/su/dsv/scipro/peer/Comment.java +++ b/core/src/main/java/se/su/dsv/scipro/peer/Comment.java @@ -1,9 +1,19 @@ package se.su.dsv.scipro.peer; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Comparator; @@ -16,12 +26,16 @@ public class Comment extends DomainObject { private Long id; @ManyToOne(optional = false) + @JoinColumn(name = "creator_user_id", referencedColumnName = "id") private User creator; + @Basic + @Column(name = "comment") @Lob private String comment; @ManyToOne(optional = false) + @JoinColumn(name = "comment_thread_id", referencedColumnName = "id") private CommentThread commentThread; protected Comment() { diff --git a/core/src/main/java/se/su/dsv/scipro/peer/CommentThread.java b/core/src/main/java/se/su/dsv/scipro/peer/CommentThread.java index d90511945c..803fb375af 100755 --- a/core/src/main/java/se/su/dsv/scipro/peer/CommentThread.java +++ b/core/src/main/java/se/su/dsv/scipro/peer/CommentThread.java @@ -8,7 +8,9 @@ import java.util.Set; import java.util.TreeSet; @Entity -@Table(name = "comment_thread", uniqueConstraints = {@UniqueConstraint(columnNames = {"commentableKey", "commentableId"})}) +@Table(name = "comment_thread", + uniqueConstraints = {@UniqueConstraint(name = "uk_comment_thread_id_key", + columnNames = {"commentable_key", "commentable_id"})}) @Cacheable(true) public class CommentThread extends DomainObject { @@ -16,11 +18,10 @@ public class CommentThread extends DomainObject { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Basic(optional = false) - @Column(length = 191) + @Column(name = "commentable_key", length = 191, nullable = false) private String commentableKey; - @Basic(optional = false) + @Column(name = "commentable_id", nullable = false) private Long commentableId; @OneToMany(mappedBy = "commentThread", orphanRemoval = true, cascade = CascadeType.ALL, targetEntity = Comment.class) diff --git a/core/src/main/java/se/su/dsv/scipro/peer/PeerRequest.java b/core/src/main/java/se/su/dsv/scipro/peer/PeerRequest.java index 8bf04b8d37..addf9fff54 100755 --- a/core/src/main/java/se/su/dsv/scipro/peer/PeerRequest.java +++ b/core/src/main/java/se/su/dsv/scipro/peer/PeerRequest.java @@ -1,7 +1,20 @@ package se.su.dsv.scipro.peer; import com.querydsl.core.annotations.QueryInit; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; import se.su.dsv.scipro.checklist.ChecklistTemplate; import se.su.dsv.scipro.data.dataobjects.Member; import se.su.dsv.scipro.file.FileReference; @@ -10,57 +23,138 @@ import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.Language; import se.su.dsv.scipro.system.User; -import jakarta.persistence.Basic; -import jakarta.persistence.Cacheable; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.Lob; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import jakarta.persistence.Table; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; @Entity @Table(name = "peer_request") @Cacheable(true) public class PeerRequest extends DomainObject { + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Lob @Basic(optional = true) + @Lob + @Column(name = "comment") private String comment; - @ManyToOne(optional = false) - @QueryInit({"headSupervisor", "projectType"}) - private Project project; - - @ManyToOne(optional = false) - private User requester; - - @ManyToOne(optional = false) - @JoinColumn(name = "file_reference_id") - private FileReference file; - - @ManyToOne(optional = true) - private ChecklistTemplate checklistTemplate; + @Enumerated(EnumType.STRING) + @Column(name = "status", nullable = false) + private RequestStatus status = RequestStatus.WAITING; @Enumerated(EnumType.STRING) private Language language; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (peer_request) referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = true) + @JoinColumn(name = "checklist_template_id", referencedColumnName = "id") + private ChecklistTemplate checklistTemplate; + + @ManyToOne(optional = false) + @JoinColumn(name = "file_reference_id", referencedColumnName = "id") + private FileReference file; + + @ManyToOne(optional = false) + @JoinColumn(name = "project_id", referencedColumnName = "id") + @QueryInit({"headSupervisor", "projectType"}) + private Project project; + + @ManyToOne(optional = false) + @JoinColumn(name = "requester_user_id", referencedColumnName = "id") + private User requester; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "peer_request" + // ---------------------------------------------------------------------------------- @OneToMany(mappedBy = "peerRequest") private List peerReviews = new ArrayList<>(1); - @Enumerated(EnumType.STRING) - @Column(nullable = false) - private RequestStatus status = RequestStatus.WAITING; + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; + } + public void setId(Long id) { + this.id = id; + } + + public String getComment() { + return this.comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public RequestStatus getStatus() { + return this.status; + } + + public void setStatus(RequestStatus status) { + this.status = status; + } + + public Language getLanguage() { + return this.language; + } + + public void setLanguage(Language language) { + this.language = language; + } + + public ChecklistTemplate getChecklistTemplate() { + return this.checklistTemplate; + } + + public void setChecklistTemplate(ChecklistTemplate checklistTemplate) { + this.checklistTemplate = checklistTemplate; + } + + public FileReference getFile() { + return this.file; + } + + public void setFile(FileReference file) { + this.file = file; + } + + public Project getProject() { + return this.project; + } + + public void setProject(Project project) { + this.project = project; + } + + public User getRequester() { + return this.requester; + } + + public void setRequester(User requester) { + this.requester = requester; + } + + public List getPeerReviews() { + return this.peerReviews; + } + + public void setPeerReviews(List peerReviews) { + this.peerReviews = peerReviews; + } + + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- public List getMembers() { List members = project.getMembers(); @@ -80,77 +174,8 @@ public class PeerRequest extends DomainObject { return null; } - @Override - public Long getId() { - return this.id; - } - - public String getComment() { - return this.comment; - } - - public Project getProject() { - return this.project; - } - - public User getRequester() { - return this.requester; - } - - public FileReference getFile() { - return this.file; - } - - public ChecklistTemplate getChecklistTemplate() { - return this.checklistTemplate; - } - - public Language getLanguage() { - return this.language; - } - - public List getPeerReviews() { - return this.peerReviews; - } - - public RequestStatus getStatus() { - return this.status; - } - - public void setId(Long id) { - this.id = id; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public void setProject(Project project) { - this.project = project; - } - - public void setRequester(User requester) { - this.requester = requester; - } - - public void setFile(FileReference file) { - this.file = file; - } - - public void setChecklistTemplate(ChecklistTemplate checklistTemplate) { - this.checklistTemplate = checklistTemplate; - } - - public void setLanguage(Language language) { - this.language = language; - } - - public void setPeerReviews(List peerReviews) { - this.peerReviews = peerReviews; - } - - public void setStatus(RequestStatus status) { - this.status = status; + protected boolean canEqual(final Object other) { + return other instanceof PeerRequest; } @Override @@ -162,10 +187,6 @@ public class PeerRequest extends DomainObject { && Objects.equals(this.getId(), other.getId()); } - protected boolean canEqual(final Object other) { - return other instanceof PeerRequest; - } - @Override public int hashCode() { return Objects.hashCode(this.getId()); @@ -173,6 +194,9 @@ public class PeerRequest extends DomainObject { @Override public String toString() { - return "PeerRequest(id=" + this.getId() + ", comment=" + this.getComment() + ", project=" + this.getProject() + ", requester=" + this.getRequester() + ", file=" + this.getFile() + ", checklistTemplate=" + this.getChecklistTemplate() + ", language=" + this.getLanguage() + ", status=" + this.getStatus() + ")"; + return "PeerRequest(id=" + this.getId() + ", comment=" + this.getComment() + ", project=" + + this.getProject() + ", requester=" + this.getRequester() + ", file=" + this.getFile() + + ", checklistTemplate=" + this.getChecklistTemplate() + ", language=" + this.getLanguage() + + ", status=" + this.getStatus() + ")"; } } diff --git a/core/src/main/java/se/su/dsv/scipro/peer/PeerReview.java b/core/src/main/java/se/su/dsv/scipro/peer/PeerReview.java index e721778e38..7ce7378d1d 100755 --- a/core/src/main/java/se/su/dsv/scipro/peer/PeerReview.java +++ b/core/src/main/java/se/su/dsv/scipro/peer/PeerReview.java @@ -1,6 +1,24 @@ package se.su.dsv.scipro.peer; import com.querydsl.core.annotations.QueryInit; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.OrderBy; +import jakarta.persistence.Table; + import se.su.dsv.scipro.checklist.ChecklistAnswerEnum; import se.su.dsv.scipro.data.dataobjects.Member; import se.su.dsv.scipro.file.FileReference; @@ -8,7 +26,6 @@ import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -23,41 +40,140 @@ public class PeerReview extends DomainObject implements Commentable { public enum ReviewStatus { IN_PROGRESS, COMPLETED, EXPIRED } - + + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - + + @Basic + @Lob + @Column(name = "comment") + private String comment; + + @Enumerated(EnumType.STRING) + @Column(name = "status") + private ReviewStatus status = ReviewStatus.IN_PROGRESS; + + @Basic(optional = false) + @Column(name = "deadline") + private Date deadline; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (peer_review) referencing other tables. + // ---------------------------------------------------------------------------------- + @OneToOne(optional=true, orphanRemoval = true, cascade = CascadeType.ALL) + @JoinColumn(name = "file_reference_id", referencedColumnName = "id") + private FileReference file; + + @ManyToOne(optional=false) + @JoinColumn(name = "peer_request_id", referencedColumnName = "id") + @QueryInit({"project.headSupervisor", "requester.user", "language", "checklistTemplate"}) + private PeerRequest peerRequest; + + @ManyToOne(optional=false) + @JoinColumn(name = "project_id", referencedColumnName = "id") + @QueryInit({"headSupervisor", "projectType"}) + private Project project; + @ManyToOne(optional=false) + @JoinColumn(name = "reviewer_user_id", referencedColumnName = "id") @QueryInit("*.*") private User reviewer; - - @ManyToOne(optional=false) - @QueryInit({"headSupervisor", "projectType"}) - private Project project; - - @ManyToOne(optional=false) - @QueryInit({"project.headSupervisor","requester.user", "language", "checklistTemplate"}) - private PeerRequest peerRequest; - + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "peer_review" + // ---------------------------------------------------------------------------------- @OneToMany(mappedBy="peerReview", orphanRemoval=true, cascade=CascadeType.ALL) @OrderBy("id") private List answers = new ArrayList<>(); - @OneToOne(optional=true, orphanRemoval = true, cascade = CascadeType.ALL) - @JoinColumn(name = "file_reference_id") - private FileReference file; - - @Lob - private String comment; + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; + } - @Enumerated(EnumType.STRING) - private ReviewStatus status = ReviewStatus.IN_PROGRESS; + public void setId(Long id) { + this.id = id; + } - @Basic(optional = false) - private Date deadline; + public String getComment() { + return this.comment; + } - @Override + public void setComment(String comment) { + this.comment = comment; + } + + public ReviewStatus getStatus() { + return status; + } + + public void setStatus(ReviewStatus status) { + this.status = status; + } + + public Date getDeadline() { + return this.deadline; + } + + public void setDeadline(Date deadline) { + this.deadline = deadline; + } + + public FileReference getFile() { + return this.file; + } + + public void setFile(FileReference file) { + this.file = file; + } + + public PeerRequest getPeerRequest() { + return this.peerRequest; + } + + public void setPeerRequest(PeerRequest peerRequest) { + this.peerRequest = peerRequest; + } + + public Project getProject() { + return this.project; + } + + public void setProject(Project project) { + this.project = project; + } + + public User getReviewer() { + return this.reviewer; + } + + public void setReviewer(User reviewer) { + this.reviewer = reviewer; + } + + public List getAnswers() { + return this.answers; + } + + public void setAnswers(List answers) { + this.answers = answers; + } + + public void addAnswer(String question) { + this.answers.add(new Answer(this, question)); + } + + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- + @Override public final String getCommentKey() { return PeerReview.class.getCanonicalName(); } @@ -73,10 +189,6 @@ public class PeerReview extends DomainObject implements Commentable { return new Date().after(getDeadline()); } - public ReviewStatus getStatus() { - return status; - } - public boolean isExpired() { return status == ReviewStatus.EXPIRED; } @@ -97,90 +209,12 @@ public class PeerReview extends DomainObject implements Commentable { setStatus(isLate() ? ReviewStatus.EXPIRED : ReviewStatus.COMPLETED); } - private static boolean isEmpty(String s) { - return s == null || s.isBlank(); - } - public void expire() { status = ReviewStatus.EXPIRED; } - public void addAnswer(String question) { - this.answers.add(new Answer(this, question)); - } - - @Override - public Long getId() { - return this.id; - } - - public User getReviewer() { - return this.reviewer; - } - - public Project getProject() { - return this.project; - } - - public PeerRequest getPeerRequest() { - return this.peerRequest; - } - - public List getAnswers() { - return this.answers; - } - - public FileReference getFile() { - return this.file; - } - - public String getComment() { - return this.comment; - } - - public Date getDeadline() { - return this.deadline; - } - - public void setId(Long id) { - this.id = id; - } - - public void setReviewer(User reviewer) { - this.reviewer = reviewer; - } - - public void setProject(Project project) { - this.project = project; - } - - public void setPeerRequest(PeerRequest peerRequest) { - this.peerRequest = peerRequest; - } - - public void setAnswers(List answers) { - this.answers = answers; - } - - public void setFile(FileReference file) { - this.file = file; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public void setStatus(ReviewStatus status) { - this.status = status; - } - - public void setDeadline(Date deadline) { - this.deadline = deadline; - } - - @Override - public String toString() { - return "PeerReview(id=" + this.getId() + ", reviewer=" + this.getReviewer() + ", project=" + this.getProject() + ", peerRequest=" + this.getPeerRequest() + ", answers=" + this.getAnswers() + ", file=" + this.getFile() + ", comment=" + this.getComment() + ", status=" + this.getStatus() + ", deadline=" + this.getDeadline() + ")"; + protected boolean canEqual(final Object other) { + return other instanceof PeerReview; } @Override @@ -192,12 +226,23 @@ public class PeerReview extends DomainObject implements Commentable { && Objects.equals(this.getId(), other.getId()); } - protected boolean canEqual(final Object other) { - return other instanceof PeerReview; + @Override + public int hashCode() { + return Objects.hashCode(this.getId()); } @Override - public int hashCode() { - return Objects.hashCode(this.getId()); + public String toString() { + return "PeerReview(id=" + this.getId() + ", reviewer=" + this.getReviewer() + ", project=" + + this.getProject() + ", peerRequest=" + this.getPeerRequest() + ", answers=" + this.getAnswers() + + ", file=" + this.getFile() + ", comment=" + this.getComment() + ", status=" + this.getStatus() + + ", deadline=" + this.getDeadline() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Static helper methods + // ---------------------------------------------------------------------------------- + private static boolean isEmpty(String s) { + return s == null || s.isBlank(); } } diff --git a/core/src/main/java/se/su/dsv/scipro/plagiarism/PlagiarismRequest.java b/core/src/main/java/se/su/dsv/scipro/plagiarism/PlagiarismRequest.java index 3356526223..1aece5bd51 100644 --- a/core/src/main/java/se/su/dsv/scipro/plagiarism/PlagiarismRequest.java +++ b/core/src/main/java/se/su/dsv/scipro/plagiarism/PlagiarismRequest.java @@ -11,46 +11,61 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToOne; import jakarta.persistence.Table; -import java.util.*; + +import java.util.Objects; @Entity @Table(name = "plagiarism_request") class PlagiarismRequest { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (plagiarism_request) referencing other + // tables. + // ---------------------------------------------------------------------------------- @OneToOne(optional = false) - @JoinColumn(name = "document_reference_id") + @JoinColumn(name = "document_file_reference_id", referencedColumnName = "id") private FileReference document; @ManyToOne + @JoinColumn(name = "receiver_user_id", referencedColumnName = "id") private User receiver; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return this.id; } - public FileReference getDocument() { - return this.document; - } - - public User getReceiver() { - return this.receiver; - } - public void setId(Long id) { this.id = id; } + public FileReference getDocument() { + return this.document; + } + public void setDocument(FileReference fileDescription) { this.document = fileDescription; } + public User getReceiver() { + return this.receiver; + } + public void setReceiver(User receiver) { this.receiver = receiver; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -62,10 +77,6 @@ class PlagiarismRequest { && Objects.equals(this.getReceiver(), other.getReceiver()); } - protected boolean canEqual(final Object other) { - return other instanceof PlagiarismRequest; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getDocument(), this.getReceiver()); @@ -73,6 +84,14 @@ class PlagiarismRequest { @Override public String toString() { - return "PlagiarismRequest(id=" + this.getId() + ", fileDescription=" + this.getDocument() + ", receiver=" + this.getReceiver() + ")"; + return "PlagiarismRequest(id=" + this.getId() + ", fileDescription=" + this.getDocument() + + ", receiver=" + this.getReceiver() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other method + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof PlagiarismRequest; } } diff --git a/core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSettings.java b/core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSettings.java index 74716b4e56..fa97b51a46 100644 --- a/core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSettings.java +++ b/core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSettings.java @@ -1,9 +1,11 @@ package se.su.dsv.scipro.plagiarism.urkund; import jakarta.persistence.Basic; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; + import java.util.Objects; @Entity @@ -15,12 +17,15 @@ public class UrkundSettings { private long id = ID; @Basic + @Column(name = "enabled") private boolean enabled = false; @Basic + @Column(name = "username") private String username; @Basic + @Column(name = "password") private String password; public boolean isEnabled() { @@ -70,6 +75,7 @@ public class UrkundSettings { @Override public String toString() { - return "UrkundSettings(id=" + this.id + ", enabled=" + this.isEnabled() + ", username=" + this.getUsername() + ", password=" + this.getPassword() + ")"; + return "UrkundSettings(id=" + this.id + ", enabled=" + this.isEnabled() + ", username=" + + this.getUsername() + ", password=" + this.getPassword() + ")"; } } diff --git a/core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmission.java b/core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmission.java index 594dd691fc..87580259a7 100644 --- a/core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmission.java +++ b/core/src/main/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmission.java @@ -17,139 +17,159 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import java.time.Instant; -import java.util.*; +import java.util.Objects; @Entity @Table(name = "urkund_submission") public class UrkundSubmission extends DomainObject { - - public enum State { - SUBMISSION_FAILED, SUBMITTED, REJECTED, ACCEPTED, ANALYZED, ERROR; - - public boolean isFinal() { - return !(this == SUBMITTED || this == ACCEPTED); - } - } - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne - private User receiver; + @Basic + @Column(name = "submitted_date", nullable = false) + private Instant submitted; @Basic - private String analysisAddress; - - @Column(nullable = false) + @Column(name = "state", nullable = false) @Enumerated(EnumType.STRING) private State state; - @Column(nullable = false) - private Instant submitted; - - @Column(nullable = false) + @Basic + @Column(name = "next_poll_date", nullable = false) private Instant nextPoll; - @Column(nullable = false) + @Basic + @Column(name = "polling_delay", nullable = false) @Enumerated(EnumType.STRING) private PollingDelay pollingDelay = PollingDelay.FIRST; - @OneToOne(optional = false) - @JoinColumn(name = "document_reference_id") - private FileReference document; - @Basic(optional = false) + @Column(name = "message") private String message; @Basic + @Column(name = "report_url") private String reportUrl; @Basic + @Column(name = "significance") private Float significance; + @Basic + @Column(name = "analysis_address") + private String analysisAddress; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (urkund_submission) referencing other + // tables. + // ---------------------------------------------------------------------------------- + @OneToOne(optional = false) + @JoinColumn(name = "document_file_reference_id", referencedColumnName = "id") + private FileReference document; + + @ManyToOne + @JoinColumn(name = "receiver_user_id", referencedColumnName = "id") + private User receiver; + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public String getAnalysisAddress() { - return this.analysisAddress; - } - - public State getState() { - return this.state; - } - - public Instant getSubmitted() { - return this.submitted; - } - - public FileReference getDocument() { - return this.document; - } - - public String getMessage() { - return this.message; - } - - public String getReportUrl() { - return this.reportUrl; - } - - public Float getSignificance() { - return this.significance; - } - - @Override - public String toString() { - return "UrkundSubmission(id=" + this.getId() + ", receiver=" + this.getReceiver() + ", analysisAddress=" + this.getAnalysisAddress() + ", state=" + this.getState() + ", submitted=" + this.getSubmitted() + ", nextPoll=" + this.getNextPoll() + ", pollingDelay=" + this.getPollingDelay() + ", fileDescription=" + this.getDocument() + ", message=" + this.getMessage() + ", reportUrl=" + this.getReportUrl() + ", significance=" + this.getSignificance() + ")"; - } - void setId(Long id) { this.id = id; } - void setReceiver(User receiver) { - this.receiver = receiver; - } - - void setAnalysisAddress(String analysisAddress) { - this.analysisAddress = analysisAddress; - } - - void setState(State state) { - this.state = state; + public Instant getSubmitted() { + return this.submitted; } void setSubmitted(Instant submitted) { this.submitted = submitted; } + public State getState() { + return this.state; + } + + void setState(State state) { + this.state = state; + } + + Instant getNextPoll() { + return this.nextPoll; + } + void setNextPoll(Instant nextPoll) { this.nextPoll = nextPoll; } + PollingDelay getPollingDelay() { + return this.pollingDelay; + } + void setPollingDelay(PollingDelay pollingDelay) { this.pollingDelay = pollingDelay; } - void setDocument(FileReference fileDescription) { - this.document = fileDescription; + public String getMessage() { + return this.message; } void setMessage(String message) { this.message = message; } + public String getReportUrl() { + return this.reportUrl; + } + void setReportUrl(String reportUrl) { this.reportUrl = reportUrl; } + public Float getSignificance() { + return this.significance; + } + void setSignificance(Float significance) { this.significance = significance; } + public String getAnalysisAddress() { + return this.analysisAddress; + } + + void setAnalysisAddress(String analysisAddress) { + this.analysisAddress = analysisAddress; + } + + public FileReference getDocument() { + return this.document; + } + + void setDocument(FileReference fileDescription) { + this.document = fileDescription; + } + + User getReceiver() { + return this.receiver; + } + + void setReceiver(User receiver) { + this.receiver = receiver; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -170,10 +190,6 @@ public class UrkundSubmission extends DomainObject { && Objects.equals(this.getSignificance(), other.getSignificance()); } - protected boolean canEqual(final Object other) { - return other instanceof UrkundSubmission; - } - @Override public int hashCode() { return Objects.hash( @@ -190,15 +206,31 @@ public class UrkundSubmission extends DomainObject { this.getSignificance()); } - User getReceiver() { - return this.receiver; + @Override + public String toString() { + return "UrkundSubmission(id=" + this.getId() + ", receiver=" + this.getReceiver() + + ", analysisAddress=" + this.getAnalysisAddress() + ", state=" + + this.getState() + ", submitted=" + this.getSubmitted() + + ", nextPoll=" + this.getNextPoll() + ", pollingDelay=" + this.getPollingDelay() + + ", fileDescription=" + this.getDocument() + ", message=" + this.getMessage() + + ", reportUrl=" + this.getReportUrl() + ", significance=" + this.getSignificance() + ")"; } - Instant getNextPoll() { - return this.nextPoll; + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof UrkundSubmission; } - PollingDelay getPollingDelay() { - return this.pollingDelay; + // ---------------------------------------------------------------------------------- + // Nested type + // ---------------------------------------------------------------------------------- + public enum State { + SUBMISSION_FAILED, SUBMITTED, REJECTED, ACCEPTED, ANALYZED, ERROR; + + public boolean isFinal() { + return !(this == SUBMITTED || this == ACCEPTED); + } } } diff --git a/core/src/main/java/se/su/dsv/scipro/project/Author.java b/core/src/main/java/se/su/dsv/scipro/project/Author.java index c3094e697c..8adaa5fed3 100644 --- a/core/src/main/java/se/su/dsv/scipro/project/Author.java +++ b/core/src/main/java/se/su/dsv/scipro/project/Author.java @@ -1,26 +1,34 @@ package se.su.dsv.scipro.project; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.io.Serializable; import java.util.Objects; @Entity @Table(name = "project_user") public class Author { + // ---------------------------------------------------------------------------------- + // Embedded JPA-mapping + // ---------------------------------------------------------------------------------- @EmbeddedId private AuthorPK authorPK; - @ManyToOne(optional = false) - @JoinColumn(name = "project_id", nullable = false) - @MapsId("projectId") - private Project project; - - @ManyToOne(optional = false) - @JoinColumn(name = "user_id", nullable = false) - @MapsId("userId") - private User user; + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- + @Basic(optional = true) + @Column(name = "reflection") + private String reflection; /** * If this author wants to be notified when a final seminar created @@ -36,15 +44,29 @@ public class Author { @Column(name = "subscribed_to_final_seminar_notifications", nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE") private boolean subscribedToFinalSeminarNotifications; - @Basic(optional = true) - private String reflection; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (project_user) referencing other + // tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + @JoinColumn(name = "project_id", nullable = false) + @MapsId("projectId") + private Project project; - public Project getProject() { - return project; + @ManyToOne(optional = false) + @JoinColumn(name = "user_id", nullable = false) + @MapsId("userId") + private User user; + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + public String getReflection() { + return reflection; } - public User getUser() { - return user; + public void setReflection(String reflection) { + this.reflection = reflection; } public boolean isSubscribedToFinalSeminarNotifications() { @@ -55,14 +77,17 @@ public class Author { this.subscribedToFinalSeminarNotifications = subscribedToFinalSeminarNotifications; } - public String getReflection() { - return reflection; + public Project getProject() { + return project; } - public void setReflection(String reflection) { - this.reflection = reflection; + public User getUser() { + return user; } + // ---------------------------------------------------------------------------------- + // Nested class + // ---------------------------------------------------------------------------------- @Embeddable public static class AuthorPK implements Serializable { private Long projectId; diff --git a/core/src/main/java/se/su/dsv/scipro/project/Project.java b/core/src/main/java/se/su/dsv/scipro/project/Project.java index 9429d2cbfc..569d1da4a7 100755 --- a/core/src/main/java/se/su/dsv/scipro/project/Project.java +++ b/core/src/main/java/se/su/dsv/scipro/project/Project.java @@ -1,13 +1,51 @@ package se.su.dsv.scipro.project; import com.querydsl.core.annotations.QueryInit; +import jakarta.persistence.AttributeOverride; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Embedded; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapKeyJoinColumn; +import jakarta.persistence.PrePersist; +import jakarta.persistence.PreUpdate; +import jakarta.persistence.Table; + import se.su.dsv.scipro.data.dataobjects.Member; import se.su.dsv.scipro.reusable.SciProUtilities; -import se.su.dsv.scipro.system.*; +import se.su.dsv.scipro.system.DegreeType; +import se.su.dsv.scipro.system.DomainObject; +import se.su.dsv.scipro.system.Language; +import se.su.dsv.scipro.system.ProjectModule; +import se.su.dsv.scipro.system.ProjectType; +import se.su.dsv.scipro.system.ResearchArea; +import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.time.LocalDate; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.stream.Collectors; @Entity @@ -18,17 +56,30 @@ public class Project extends DomainObject { public static final String NO_CO_SUPERVISOR = "No co-supervisor"; public static final int TITLE_MAX_LENGTH = 255; + public static ITitle builder() { + return new Builder(); + } + + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(unique = true) - private Integer identifier; - - @Column(length = TITLE_MAX_LENGTH) @Basic(optional = false) + @Column(name = "title", length = TITLE_MAX_LENGTH) private String title; + @Basic + @Column(name = "credits") + private int credits; + + @Basic + @Column(name = "language") + @Enumerated(EnumType.STRING) + private Language language; + @Basic(optional = false) @Column(name = "start_date", nullable = false) private LocalDate startDate; @@ -37,61 +88,91 @@ public class Project extends DomainObject { @Column(name = "expected_end_date") private LocalDate expectedEndDate; - @ManyToMany - @JoinTable(name = "project_user", inverseJoinColumns = @JoinColumn(name = "user_id")) - private Set projectParticipants = new TreeSet<>(new User.ByNameComparator()); - - @ManyToMany - @JoinTable(name = "project_reviewer", inverseJoinColumns = @JoinColumn(name = "user_id")) - private Set reviewers = new TreeSet<>(new User.ByNameComparator()); - - @ManyToMany - @JoinTable(name = "project_cosupervisor", inverseJoinColumns = @JoinColumn(name = "user_id")) - private Set coSupervisors = new TreeSet<>(new User.ByNameComparator()); - - @ManyToOne(optional = false) - @QueryInit({"unit"}) - @JoinColumn(name = "supervisor_id") - private User headSupervisor; - + @Basic + @Column(name = "project_status") @Enumerated(EnumType.STRING) private ProjectStatus projectStatus = ProjectStatus.ACTIVE; + @Basic + @Column(name = "final_seminar_rule_exmpt") + private boolean finalSeminarRuleExempted = false; + + @Basic + @Column(name = "state_of_mind") @Enumerated(EnumType.STRING) private StateOfMind stateOfMind = StateOfMind.FINE; @Basic(optional = true) - private Date stateOfMindDate; - - @Basic(optional = true) + @Column(name = "state_of_mind_reason") private String stateOfMindReason; - @ManyToOne(optional = false) - private ProjectType projectType; - - @Embedded - @AttributeOverride(name = "name", column = @Column(name = "externalOrganization")) - private ExternalOrganization externalOrganization; - - @Column(name = "fs_rule_exmpt") - private boolean finalSeminarRuleExempted = false; + @Basic(optional = true) + @Column(name = "state_of_mind_date") + private Date stateOfMindDate; @Basic - private int credits; + @Column(name = "daisy_identifier", unique = true) + private Integer identifier; + + // ---------------------------------------------------------------------------------- + // Embedded JPA-mapping + // ---------------------------------------------------------------------------------- + @Embedded + @AttributeOverride(name = "name", column = @Column(name = "external_organization")) + private ExternalOrganization externalOrganization; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (opposition_report) referencing other + // tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + @JoinColumn(name = "project_type_id", referencedColumnName = "id") + private ProjectType projectType; @ManyToOne(optional = true) + @JoinColumn(name = "research_area_id", referencedColumnName = "id") private ResearchArea researchArea; - @Enumerated(EnumType.STRING) - private Language language; + @ManyToOne(optional = false) + @JoinColumn(name = "supervisor_id", referencedColumnName = "id") + @QueryInit({"unit"}) + private User headSupervisor; + // ---------------------------------------------------------------------------------- + // @ManyToMany JPA-mappings + // ---------------------------------------------------------------------------------- + @ManyToMany + @JoinTable(name = "project_user", + joinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id")) + private Set projectParticipants = new TreeSet<>(new User.ByNameComparator()); + + @ManyToMany + @JoinTable(name = "project_reviewer", + joinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id")) + private Set reviewers = new TreeSet<>(new User.ByNameComparator()); + + @ManyToMany + @JoinTable(name = "project_cosupervisor", + joinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id")) + private Set coSupervisors = new TreeSet<>(new User.ByNameComparator()); + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "project" + // ---------------------------------------------------------------------------------- @ElementCollection(fetch = FetchType.LAZY) - @CollectionTable(name = "project_user_note", joinColumns = @JoinColumn(name = "project_id")) + @CollectionTable(name = "project_user_note", + joinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id")) @Column(name = "note") @SuppressWarnings("JpaDataSourceORMInspection") // false warning from IntelliJ for the @MapKeyJoinColumn @MapKeyJoinColumn(name = "user_id") private Map userNotes = new HashMap<>(); + // ---------------------------------------------------------------------------------- + // JPA Lifecycle Methods + // ---------------------------------------------------------------------------------- @PrePersist @PreUpdate void cleanTitle() { @@ -101,12 +182,67 @@ public class Project extends DomainObject { title = title.trim(); } - public Map getUserNotes() { - return userNotes; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; } - public void setUserNotes(Map userNotes) { - this.userNotes = userNotes; + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return SciProUtilities.cleanString(title); + } + + public void setTitle(String title) { + this.title = title; + } + + public int getCredits() { + return this.credits; + } + + public void setCredits(int credits) { + this.credits = credits; + } + + public Language getLanguage() { + return this.language; + } + + public void setLanguage(Language language) { + this.language = language; + } + + public LocalDate getStartDate() { + return startDate; + } + + public void setStartDate(LocalDate startDate) { + this.startDate = startDate; + } + + public LocalDate getExpectedEndDate() { + return this.expectedEndDate; + } + + public void setExpectedEndDate(LocalDate expectedEndDate) { + this.expectedEndDate = expectedEndDate; + } + + public ProjectStatus getProjectStatus() { + return this.projectStatus; + } + + public void setProjectStatus(ProjectStatus projectStatus) { + this.projectStatus = projectStatus; + if (projectStatus == ProjectStatus.COMPLETED) { + this.stateOfMind = StateOfMind.FINE; + } } public boolean isFinalSeminarRuleExempted() { @@ -117,53 +253,20 @@ public class Project extends DomainObject { this.finalSeminarRuleExempted = finalSeminarRuleExempted; } - public User getHeadSupervisor() { - return headSupervisor; + public StateOfMind getStateOfMind() { + return this.stateOfMind; } - public ProjectType getProjectType() { - return projectType; + public void setStateOfMind(StateOfMind stateOfMind) { + this.stateOfMind = stateOfMind; } - public SortedSet getCoSupervisors() { - TreeSet s = new TreeSet<>(new User.ByNameComparator()); - s.addAll(coSupervisors); - return Collections.unmodifiableSortedSet(s); + public String getStateOfMindReason() { + return this.stateOfMindReason; } - public void setCoSupervisors(Collection coSupervisors) { - this.coSupervisors.clear(); - this.coSupervisors.addAll(coSupervisors); - } - - public void addCoSupervisor(User coSupervisor) { - coSupervisors.add(coSupervisor); - } - - public SortedSet getReviewers() { - TreeSet s = new TreeSet<>(new User.ByNameComparator()); - s.addAll(reviewers); - return Collections.unmodifiableSortedSet(s); - } - - public void setReviewers(Collection reviewers) { - this.reviewers.clear(); - this.reviewers.addAll(reviewers); - } - - public void addReviewer(User reviewer) { - reviewers.add(reviewer); - } - - public void removeReviewer(User reviewer) { - reviewers.remove(reviewer); - } - - public void setProjectStatus(ProjectStatus projectStatus) { - this.projectStatus = projectStatus; - if (projectStatus == ProjectStatus.COMPLETED) { - this.stateOfMind = StateOfMind.FINE; - } + public void setStateOfMindReason(String stateOfMindReason) { + this.stateOfMindReason = stateOfMindReason; } public Date getStateOfMindDate() { @@ -176,8 +279,44 @@ public class Project extends DomainObject { : new Date(stateOfMindDate.getTime()); } - public String getTitle() { - return SciProUtilities.cleanString(title); + public Integer getIdentifier() { + return this.identifier; + } + + public void setIdentifier(Integer identifier) { + this.identifier = identifier; + } + + public ExternalOrganization getExternalOrganization() { + return this.externalOrganization; + } + + public void setExternalOrganization(ExternalOrganization externalOrganization) { + this.externalOrganization = externalOrganization; + } + + public ProjectType getProjectType() { + return projectType; + } + + public void setProjectType(ProjectType projectType) { + this.projectType = projectType; + } + + public ResearchArea getResearchArea() { + return this.researchArea; + } + + public void setResearchArea(ResearchArea researchArea) { + this.researchArea = researchArea; + } + + public User getHeadSupervisor() { + return headSupervisor; + } + + public void setHeadSupervisor(User headSupervisor) { + this.headSupervisor = headSupervisor; } public SortedSet getProjectParticipants() { @@ -191,11 +330,91 @@ public class Project extends DomainObject { this.projectParticipants.addAll(projectParticipants); } + public SortedSet getReviewers() { + TreeSet s = new TreeSet<>(new User.ByNameComparator()); + s.addAll(reviewers); + return Collections.unmodifiableSortedSet(s); + } + + public void setReviewers(Collection reviewers) { + this.reviewers.clear(); + this.reviewers.addAll(reviewers); + } + + public SortedSet getCoSupervisors() { + TreeSet s = new TreeSet<>(new User.ByNameComparator()); + s.addAll(coSupervisors); + return Collections.unmodifiableSortedSet(s); + } + + public void setCoSupervisors(Collection coSupervisors) { + this.coSupervisors.clear(); + this.coSupervisors.addAll(coSupervisors); + } + + public Map getUserNotes() { + return userNotes; + } + + public void setUserNotes(Map userNotes) { + this.userNotes = userNotes; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Project)) return false; + final Project other = (Project) o; + return other.canEqual(this) + && Objects.equals(this.getId(), other.getId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.getId()); + } + + @Override + public String toString() { + return "Project(id=" + this.getId() + ", identifier=" + this.getIdentifier() + + ", title=" + this.getTitle() + ", projectParticipants=" + this.getProjectParticipants() + + ", headSupervisor=" + this.getHeadSupervisor() + ", projectType=" + + this.getProjectType() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + + protected boolean canEqual(final Object other) { + return other instanceof Project; + } + public void addProjectParticipant(User s) { projectParticipants.add(s); } - //TODO remove this method + public boolean isParticipant(User user) { + for (User s : projectParticipants) { + if (s.equals(user)) { + return true; + } + } + return false; + } + + public void addReviewer(User reviewer) { + reviewers.add(reviewer); + } + + public void removeReviewer(User reviewer) { + reviewers.remove(reviewer); + } + + // TODO remove this method public User getReviewer() { if (reviewers.isEmpty()) { return null; @@ -204,6 +423,14 @@ public class Project extends DomainObject { } } + public String getReviewerName() { + return getReviewer() != null ? getReviewer().getFullName() : NO_REVIEWER; + } + + public void addCoSupervisor(User coSupervisor) { + coSupervisors.add(coSupervisor); + } + public List getMembers() { List members = new ArrayList<>(); @@ -240,23 +467,10 @@ public class Project extends DomainObject { return externalOrganization != null; } - public boolean isParticipant(User user) { - for (User s : projectParticipants) { - if (s.equals(user)) { - return true; - } - } - return false; - } - public String getSupervisorName() { return getHeadSupervisor().getFullName(); } - public String getReviewerName() { - return getReviewer() != null ? getReviewer().getFullName() : NO_REVIEWER; - } - public DegreeType getProjectTypeDegreeType() { return getProjectType().getDegreeType(); } @@ -289,10 +503,6 @@ public class Project extends DomainObject { return getProjectType().hasModule(projectModule); } - public static ITitle builder() { - return new Builder(); - } - public boolean isSupervisor(User user) { return headSupervisor != null && headSupervisor.equals(user); } @@ -319,125 +529,9 @@ public class Project extends DomainObject { return Objects.requireNonNullElse(language, getProjectType().getDefaultLanguage()); } - @Override - public Long getId() { - return this.id; - } - - public Integer getIdentifier() { - return this.identifier; - } - - public LocalDate getExpectedEndDate() { - return this.expectedEndDate; - } - - public ProjectStatus getProjectStatus() { - return this.projectStatus; - } - - public StateOfMind getStateOfMind() { - return this.stateOfMind; - } - - public String getStateOfMindReason() { - return this.stateOfMindReason; - } - - public ExternalOrganization getExternalOrganization() { - return this.externalOrganization; - } - - public int getCredits() { - return this.credits; - } - - public ResearchArea getResearchArea() { - return this.researchArea; - } - - public Language getLanguage() { - return this.language; - } - - public void setId(Long id) { - this.id = id; - } - - public void setIdentifier(Integer identifier) { - this.identifier = identifier; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setExpectedEndDate(LocalDate expectedEndDate) { - this.expectedEndDate = expectedEndDate; - } - - public void setHeadSupervisor(User headSupervisor) { - this.headSupervisor = headSupervisor; - } - - public void setStateOfMind(StateOfMind stateOfMind) { - this.stateOfMind = stateOfMind; - } - - public void setStateOfMindReason(String stateOfMindReason) { - this.stateOfMindReason = stateOfMindReason; - } - - public void setProjectType(ProjectType projectType) { - this.projectType = projectType; - } - - public void setExternalOrganization(ExternalOrganization externalOrganization) { - this.externalOrganization = externalOrganization; - } - - public void setCredits(int credits) { - this.credits = credits; - } - - public void setResearchArea(ResearchArea researchArea) { - this.researchArea = researchArea; - } - - public void setLanguage(Language language) { - this.language = language; - } - - public LocalDate getStartDate() { - return startDate; - } - - public void setStartDate(LocalDate startDate) { - this.startDate = startDate; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof Project)) return false; - final Project other = (Project) o; - return other.canEqual(this) - && Objects.equals(this.getId(), other.getId()); - } - - protected boolean canEqual(final Object other) { - return other instanceof Project; - } - - @Override - public int hashCode() { - return Objects.hashCode(this.getId()); - } - - @Override - public String toString() { - return "Project(id=" + this.getId() + ", identifier=" + this.getIdentifier() + ", title=" + this.getTitle() + ", projectParticipants=" + this.getProjectParticipants() + ", headSupervisor=" + this.getHeadSupervisor() + ", projectType=" + this.getProjectType() + ")"; - } + // ---------------------------------------------------------------------------------- + // Nested classes and interfaces + // ---------------------------------------------------------------------------------- private static class Builder implements ITitle, IProjectType, IStartDate, IBuild { private final Project instance = new Project(); diff --git a/core/src/main/java/se/su/dsv/scipro/projectpartner/ProjectPartner.java b/core/src/main/java/se/su/dsv/scipro/projectpartner/ProjectPartner.java index 0afe97861e..643956fe8e 100755 --- a/core/src/main/java/se/su/dsv/scipro/projectpartner/ProjectPartner.java +++ b/core/src/main/java/se/su/dsv/scipro/projectpartner/ProjectPartner.java @@ -1,15 +1,26 @@ package se.su.dsv.scipro.projectpartner; +import java.util.Objects; + +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import se.su.dsv.scipro.match.ApplicationPeriod; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; -import java.util.Objects; - @Entity -@Table(name="projectPartner") +@Table(name="project_partner") @Cacheable(true) public class ProjectPartner extends DomainObject { @Id @@ -20,17 +31,19 @@ public class ProjectPartner extends DomainObject { private User user; @ManyToOne(optional = false) + @JoinColumn(name = "project_type_id") private ProjectType projectType; @ManyToOne(optional = false) + @JoinColumn(name = "application_period_id") private ApplicationPeriod applicationPeriod; @Lob - @Basic(optional=false) + @Column(name = "info_text", nullable=false) private String infotext; @Basic(optional = false) - @Column(nullable = false, name = "active") + @Column(name = "active", nullable = false) private boolean active = true; public ProjectPartner(User user){ diff --git a/core/src/main/java/se/su/dsv/scipro/report/AbstractCriterion.java b/core/src/main/java/se/su/dsv/scipro/report/AbstractCriterion.java index 7fd640236b..e9d80f2699 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/AbstractCriterion.java +++ b/core/src/main/java/se/su/dsv/scipro/report/AbstractCriterion.java @@ -1,12 +1,12 @@ package se.su.dsv.scipro.report; -import jakarta.persistence.GenerationType; -import se.su.dsv.scipro.system.DomainObject; - import jakarta.persistence.Basic; +import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; +import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.Language; import java.io.Serializable; @@ -15,19 +15,28 @@ import java.util.Objects; @MappedSuperclass public abstract class AbstractCriterion extends DomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Basic(optional = false) + @Basic + @Column(name = "title_sv", nullable = false) private String title; - @Basic(optional = false) + @Basic + @Column(name = "title_en", nullable = false) private String titleEn; - @Basic(optional = false) + @Basic + @Column(name = "sort_order", nullable = false) private Integer sortOrder; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected AbstractCriterion() { } @@ -37,6 +46,9 @@ public abstract class AbstractCriterion extends DomainObject { this.sortOrder = sortOrder; } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; @@ -50,14 +62,13 @@ public abstract class AbstractCriterion extends DomainObject { return titleEn; } - public String getTitle(Language language) { - return language == Language.ENGLISH ? getTitleEn() : getTitle(); - } - public Integer getSortOrder() { return this.sortOrder; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -71,10 +82,6 @@ public abstract class AbstractCriterion extends DomainObject { && Objects.equals(this.getSortOrder(), other.getSortOrder()); } - protected boolean canEqual(final Object other) { - return other instanceof AbstractCriterion; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getTitle(), this.getTitleEn(), this.getSortOrder()); @@ -85,6 +92,20 @@ public abstract class AbstractCriterion extends DomainObject { return "AbstractCriterion(id=" + this.getId() + ", title=" + this.getTitle() + ", titleEn=" + this.getTitleEn() + ", sortOrder=" + this.getSortOrder() + ")"; } + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof AbstractCriterion; + } + + public String getTitle(Language language) { + return language == Language.ENGLISH ? getTitleEn() : getTitle(); + } + + // ---------------------------------------------------------------------------------- + // Embedded class + // ---------------------------------------------------------------------------------- public static class BySortOrderComparator implements Comparator, Serializable { @Override public int compare(AbstractCriterion o1, AbstractCriterion o2) { diff --git a/core/src/main/java/se/su/dsv/scipro/report/AbstractGradingCriterion.java b/core/src/main/java/se/su/dsv/scipro/report/AbstractGradingCriterion.java index 64d2f0433b..81b55d0982 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/AbstractGradingCriterion.java +++ b/core/src/main/java/se/su/dsv/scipro/report/AbstractGradingCriterion.java @@ -8,7 +8,109 @@ import jakarta.persistence.MappedSuperclass; @MappedSuperclass public abstract class AbstractGradingCriterion extends AbstractCriterion { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- + @Basic(optional = false) + @Column(name = "points_required_to_pass", nullable = false) + protected int pointsRequiredToPass; + @Basic + @Column(name = "fx") + private boolean fx = true; + + @Basic + @Column(name = "flag") + @Enumerated(EnumType.STRING) + private Flag flag; + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- + protected AbstractGradingCriterion() { + + } + + protected AbstractGradingCriterion(String title, String titleEn, int sortOrder, int pointsRequiredToPass) { + super(title, titleEn, sortOrder); + this.pointsRequiredToPass = pointsRequiredToPass; + } + + protected AbstractGradingCriterion(String title, String titleEn, Integer sortOrder, int pointsRequiredToPass, + Flag flag) { + this(title, titleEn, sortOrder, pointsRequiredToPass); + this.flag = flag; + } + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + public int getPointsRequiredToPass() { + return this.pointsRequiredToPass; + } + + public boolean isFx() { + return this.fx; + } + + public void setFx(boolean fx) { + this.fx = fx; + } + + public Flag getFlag() { + return flag; + } + + public void setFlag(Flag flag) { + this.flag = flag; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof AbstractGradingCriterion)) return false; + final AbstractGradingCriterion other = (AbstractGradingCriterion) o; + return other.canEqual(this) + && super.equals(o) + && this.getPointsRequiredToPass() == other.getPointsRequiredToPass() + && this.isFx() == other.isFx(); + } + + @Override + public int hashCode() { + final int PRIME = 59; + int result = super.hashCode(); + result = result * PRIME + this.getPointsRequiredToPass(); + result = result * PRIME + (this.isFx() ? 79 : 97); + return result; + } + + @Override + public String toString() { + return "AbstractGradingCriterion(pointsRequiredToPass=" + this.getPointsRequiredToPass() + + ", fx=" + this.isFx() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + @Override + protected boolean canEqual(final Object other) { + return other instanceof AbstractGradingCriterion; + } + + public abstract boolean isProjectCriterion(); + + public abstract boolean isIndividualCriterion(); + + public abstract int getMaxPoints(); + + // ---------------------------------------------------------------------------------- + // Nested type + // ---------------------------------------------------------------------------------- public enum Flag { /** * Criterion marked with this flag will add extra functionality related @@ -25,91 +127,4 @@ public abstract class AbstractGradingCriterion extends AbstractCriterion { */ OPPOSITION } - - @Basic(optional = false) - protected int pointsRequiredToPass; - - @Basic - private boolean fx = true; - - @Basic - @Column(name = "flag") - @Enumerated(EnumType.STRING) - private Flag flag; - - protected AbstractGradingCriterion() { - - } - - protected AbstractGradingCriterion(String title, String titleEn, int sortOrder, int pointsRequiredToPass) { - super(title, titleEn, sortOrder); - this.pointsRequiredToPass = pointsRequiredToPass; - } - - protected AbstractGradingCriterion( - String title, - String titleEn, - Integer sortOrder, - int pointsRequiredToPass, - Flag flag) - { - this(title, titleEn, sortOrder, pointsRequiredToPass); - this.flag = flag; - } - - public abstract boolean isProjectCriterion(); - - public abstract boolean isIndividualCriterion(); - - public abstract int getMaxPoints(); - - public int getPointsRequiredToPass() { - return this.pointsRequiredToPass; - } - - public boolean isFx() { - return this.fx; - } - - public Flag getFlag() { - return flag; - } - - public void setFlag(Flag flag) { - this.flag = flag; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof AbstractGradingCriterion)) return false; - final AbstractGradingCriterion other = (AbstractGradingCriterion) o; - return other.canEqual(this) - && super.equals(o) - && this.getPointsRequiredToPass() == other.getPointsRequiredToPass() - && this.isFx() == other.isFx(); - } - - @Override - protected boolean canEqual(final Object other) { - return other instanceof AbstractGradingCriterion; - } - - @Override - public int hashCode() { - final int PRIME = 59; - int result = super.hashCode(); - result = result * PRIME + this.getPointsRequiredToPass(); - result = result * PRIME + (this.isFx() ? 79 : 97); - return result; - } - - @Override - public String toString() { - return "AbstractGradingCriterion(pointsRequiredToPass=" + this.getPointsRequiredToPass() + ", fx=" + this.isFx() + ")"; - } - - public void setFx(boolean fx) { - this.fx = fx; - } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/AbstractGradingCriterionPoint.java b/core/src/main/java/se/su/dsv/scipro/report/AbstractGradingCriterionPoint.java index ae653266ac..29e423d0f2 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/AbstractGradingCriterionPoint.java +++ b/core/src/main/java/se/su/dsv/scipro/report/AbstractGradingCriterionPoint.java @@ -1,70 +1,86 @@ package se.su.dsv.scipro.report; -import se.su.dsv.scipro.system.DomainObject; - -import jakarta.persistence.*; -import se.su.dsv.scipro.system.Language; - import java.util.Objects; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import se.su.dsv.scipro.system.DomainObject; + +import se.su.dsv.scipro.system.Language; + @MappedSuperclass -public abstract class AbstractGradingCriterionPoint extends DomainObject implements Comparable { +public abstract class AbstractGradingCriterionPoint extends DomainObject + implements Comparable { public static final int DESCRIPTION_LENGTH = 600; + + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Basic(optional = false) + @Column(name = "point") private Integer point; @Basic - @Column(length = DESCRIPTION_LENGTH) + @Column(name = "description_sv", length = DESCRIPTION_LENGTH) private String description; @Basic - @Column(length = DESCRIPTION_LENGTH) + @Column(name = "description_en", length = DESCRIPTION_LENGTH) private String descriptionEn; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- public AbstractGradingCriterionPoint() { } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return id; } - public Integer getPoint() { - return this.point; - } - - public String getDescription() { - return this.description; - } - - public String getDescriptionEn() { - return descriptionEn; - } - - public String getDescription(Language language) { - return language == Language.ENGLISH ? getDescriptionEn() : getDescription(); - } - public void setId(Long id) { this.id = id; } + public Integer getPoint() { + return this.point; + } + public void setPoint(Integer point) { this.point = point; } + public String getDescription() { + return this.description; + } + public void setDescription(String description) { this.description = description; } + public String getDescriptionEn() { + return descriptionEn; + } + public void setDescriptionEn(String descriptionEn) { this.descriptionEn = descriptionEn; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects and Comparable + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -78,10 +94,6 @@ public abstract class AbstractGradingCriterionPoint extends DomainObject impleme && Objects.equals(this.getDescriptionEn(), other.getDescriptionEn()); } - protected boolean canEqual(final Object other) { - return other instanceof AbstractGradingCriterionPoint; - } - @Override public int hashCode() { return Objects.hash(super.hashCode(), this.getId(), this.getPoint(), this.getDescription(), this.getDescriptionEn()); @@ -91,4 +103,15 @@ public abstract class AbstractGradingCriterionPoint extends DomainObject impleme public String toString() { return "AbstractGradingCriterionPoint(id=" + this.getId() + ", point=" + this.getPoint() + ", description=" + this.getDescription() + ", descriptionEn=" + this.getDescriptionEn() + ")"; } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof AbstractGradingCriterionPoint; + } + + public String getDescription(Language language) { + return language == Language.ENGLISH ? getDescriptionEn() : getDescription(); + } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/AttachmentReport.java b/core/src/main/java/se/su/dsv/scipro/report/AttachmentReport.java index 3ec5ea0ac4..53c135a971 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/AttachmentReport.java +++ b/core/src/main/java/se/su/dsv/scipro/report/AttachmentReport.java @@ -6,16 +6,23 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.JoinColumn; import jakarta.persistence.MappedSuperclass; import jakarta.persistence.OneToOne; -import java.util.*; +import java.util.Objects; @MappedSuperclass public abstract class AttachmentReport extends Report { + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in table of children class (OppositionReport) + // referencing other tables. + // ---------------------------------------------------------------------------------- @OneToOne(optional = true, cascade = CascadeType.ALL) - @JoinColumn(name = "attachment_reference_id") + @JoinColumn(name = "attachment_file_reference_id", referencedColumnName = "id") private FileReference attachment; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public FileReference getAttachment() { return this.attachment; } @@ -24,6 +31,9 @@ public abstract class AttachmentReport extends Report { this.attachment = attachment; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -34,14 +44,16 @@ public abstract class AttachmentReport extends Report { && Objects.equals(this.attachment, other.attachment); } - @Override - protected boolean canEqual(final Object other) { - return other instanceof AttachmentReport; - } - @Override public int hashCode() { return Objects.hash(super.hashCode(), this.attachment); } + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + @Override + protected boolean canEqual(final Object other) { + return other instanceof AttachmentReport; + } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/Criterion.java b/core/src/main/java/se/su/dsv/scipro/report/Criterion.java index de823bdb5c..63978c9170 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/Criterion.java +++ b/core/src/main/java/se/su/dsv/scipro/report/Criterion.java @@ -1,6 +1,11 @@ package se.su.dsv.scipro.report; -import jakarta.persistence.*; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.Language; import java.util.Objects; @@ -8,26 +13,34 @@ import java.util.Objects; @Entity @Table(name = "criterion") public class Criterion extends AbstractCriterion { - public static final int DESCRIPTION_LENGTH = 2000; - @ManyToOne(optional = false) - private Report report; - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Basic - @Column - private String feedback; - - @Basic - @Column(length = DESCRIPTION_LENGTH) + @Column(name = "description_sv", length = DESCRIPTION_LENGTH) private String description; @Basic - @Column(length = DESCRIPTION_LENGTH) + @Column(name = "description_en", length = DESCRIPTION_LENGTH) private String descriptionEn; - protected Criterion() { + @Basic + @Column(name = "feedback") + private String feedback; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (criterion) referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + @JoinColumn(name ="report_id", referencedColumnName = "id") + private Report report; + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- + protected Criterion() { } Criterion(Report report, String title, String titleEn, String description, String descriptionEn, int sortOrder) { @@ -41,22 +54,9 @@ public class Criterion extends AbstractCriterion { this(report, gradingCriterionTemplate.getTitle(), gradingCriterionTemplate.getTitleEn(), gradingCriterionTemplate.getDescription(), gradingCriterionTemplate.getDescriptionEn(), gradingCriterionTemplate.getSortOrder()); } - public void setFeedback(final String feedback) { - this.feedback = feedback; - } - - public boolean isFilledOut() { - return feedback != null && !feedback.isEmpty(); - } - - public Report getReport() { - return this.report; - } - - public String getFeedback() { - return this.feedback; - } - + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public String getDescription() { return this.description; } @@ -65,10 +65,21 @@ public class Criterion extends AbstractCriterion { return this.descriptionEn; } - public String getDescription(Language language) { - return language == Language.ENGLISH ? getDescriptionEn() : getDescription(); + public String getFeedback() { + return this.feedback; } + public void setFeedback(final String feedback) { + this.feedback = feedback; + } + + public Report getReport() { + return this.report; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -82,11 +93,6 @@ public class Criterion extends AbstractCriterion { && Objects.equals(this.getDescriptionEn(), other.getDescriptionEn()); } - @Override - protected boolean canEqual(final Object other) { - return other instanceof Criterion; - } - @Override public int hashCode() { return Objects.hash(this.getReport(), this.getFeedback(), this.getDescription(), this.getDescriptionEn()); @@ -94,6 +100,24 @@ public class Criterion extends AbstractCriterion { @Override public String toString() { - return "Criterion(report=" + this.getReport() + ", feedback=" + this.getFeedback() + ", description=" + this.getDescription() + ", descriptionEn=" + this.getDescriptionEn() + ")"; + return "Criterion(report=" + this.getReport() + ", feedback=" + this.getFeedback() + + ", description=" + this.getDescription() + ", descriptionEn=" + + this.getDescriptionEn() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + @Override + protected boolean canEqual(final Object other) { + return other instanceof Criterion; + } + + public String getDescription(Language language) { + return language == Language.ENGLISH ? getDescriptionEn() : getDescription(); + } + + public boolean isFilledOut() { + return feedback != null && !feedback.isEmpty(); } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/GradeLimit.java b/core/src/main/java/se/su/dsv/scipro/report/GradeLimit.java index 49d6b60097..385d4941f3 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/GradeLimit.java +++ b/core/src/main/java/se/su/dsv/scipro/report/GradeLimit.java @@ -1,5 +1,6 @@ package se.su.dsv.scipro.report; +import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -8,18 +9,26 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; @Entity -@Table(name = "grading_report_template_grade_limits") +@Table(name = "grading_report_template_grade_limit") public class GradeLimit { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic @Column(name = "grade") private String grade; + @Basic @Column(name = "lower_limit") private int lowerLimit; + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } diff --git a/core/src/main/java/se/su/dsv/scipro/report/GradingCriterion.java b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterion.java index aad898db4c..10ea7059b0 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/GradingCriterion.java +++ b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterion.java @@ -1,30 +1,57 @@ package se.su.dsv.scipro.report; -import jakarta.persistence.*; +import jakarta.persistence.Basic; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.DiscriminatorColumn; +import jakarta.persistence.Entity; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; + import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; @Entity -@DiscriminatorColumn(name = "type") +@Table(name = "grading_criterion") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "type") public abstract class GradingCriterion extends AbstractGradingCriterion { public static final int FEEDBACK_LENGTH = 2000; - @ManyToOne(optional = false) - private GradingReport gradingReport; - - @OneToMany(mappedBy = "gradingCriterion", orphanRemoval = true, cascade = CascadeType.PERSIST) - private List gradingCriterionPoints = new ArrayList<>(); - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Basic + @Column(name = "points") private Integer points; @Basic - @Column(length = FEEDBACK_LENGTH) + @Column(name = "feedback", length = FEEDBACK_LENGTH) private String feedback; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (grading_criterion) referencing other + // tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + @JoinColumn(name = "grading_report_id", referencedColumnName = "id") + private GradingReport gradingReport; + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "grading_criterion" + // ---------------------------------------------------------------------------------- + @OneToMany(mappedBy = "gradingCriterion", orphanRemoval = true, cascade = CascadeType.PERSIST) + private List gradingCriterionPoints = new ArrayList<>(); + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected GradingCriterion() { // JPA } @@ -41,6 +68,71 @@ public abstract class GradingCriterion extends AbstractGradingCriterion { } } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + public Integer getPoints() { + return this.points; + } + + public void setPoints(Integer points) { + this.points = points; + } + + public String getFeedback() { + return this.feedback; + } + + public void setFeedback(String feedback) { + this.feedback = feedback; + } + + public List getGradingCriterionPoints() { + return this.gradingCriterionPoints; + } + + public GradingReport getGradingReport() { + return this.gradingReport; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof GradingCriterion)) return false; + final GradingCriterion other = (GradingCriterion) o; + return other.canEqual(this) + && super.equals(o) + && Objects.equals(this.getGradingReport(), other.getGradingReport()) + && Objects.equals(this.getPoints(), other.getPoints()) + && Objects.equals(this.getFeedback(), other.getFeedback()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), this.getGradingReport(), this.getPoints(), this.getFeedback()); + } + + @Override + public String toString() { + return "GradingCriterion(gradingReport=" + this.getGradingReport() + ", points=" + this.getPoints() + + ", feedback=" + this.getFeedback() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + @Override + protected boolean canEqual(final Object other) { + return other instanceof GradingCriterion; + } + + public boolean isPassFail() { + return getMaxPoints() == 1 && getPointsRequiredToPass() == 1; + } + public boolean meetsMinimumPointRequirement() { return Objects.requireNonNullElse(getPoints(), 0) >= getPointsRequiredToPass(); } @@ -57,59 +149,4 @@ public abstract class GradingCriterion extends AbstractGradingCriterion { public int getMaxPoints() { return Collections.max(gradingCriterionPoints).getPoint(); } - - public GradingReport getGradingReport() { - return this.gradingReport; - } - - public Integer getPoints() { - return this.points; - } - - public String getFeedback() { - return this.feedback; - } - - public List getGradingCriterionPoints() { - return this.gradingCriterionPoints; - } - - public void setPoints(Integer points) { - this.points = points; - } - - public void setFeedback(String feedback) { - this.feedback = feedback; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof GradingCriterion)) return false; - final GradingCriterion other = (GradingCriterion) o; - return other.canEqual(this) - && super.equals(o) - && Objects.equals(this.getGradingReport(), other.getGradingReport()) - && Objects.equals(this.getPoints(), other.getPoints()) - && Objects.equals(this.getFeedback(), other.getFeedback()); - } - - @Override - protected boolean canEqual(final Object other) { - return other instanceof GradingCriterion; - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), this.getGradingReport(), this.getPoints(), this.getFeedback()); - } - - @Override - public String toString() { - return "GradingCriterion(gradingReport=" + this.getGradingReport() + ", points=" + this.getPoints() + ", feedback=" + this.getFeedback() + ")"; - } - - public boolean isPassFail() { - return getMaxPoints() == 1 && getPointsRequiredToPass() == 1; - } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionPoint.java b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionPoint.java index 5c8734af9b..6c516f95b4 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionPoint.java +++ b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionPoint.java @@ -1,37 +1,39 @@ package se.su.dsv.scipro.report; import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import java.util.Objects; @Entity -@Table(name = "GradingCriterionPoint") +@Table(name = "grading_criterion_point") public class GradingCriterionPoint extends AbstractGradingCriterionPoint { - + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (grading_criterion_point) referencing other + // tables. + // ---------------------------------------------------------------------------------- @ManyToOne(optional = false) + @JoinColumn(name = "grading_criterion_id", referencedColumnName = "id") private GradingCriterion gradingCriterion; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- public GradingCriterionPoint() { } - public GradingCriterionPoint( - final Integer point, - final String description, - final String descriptionEn, - final GradingCriterion gradingCriterion) - { + public GradingCriterionPoint(final Integer point, final String description, + final String descriptionEn, final GradingCriterion gradingCriterion) { setPoint(point); setDescription(description); setDescriptionEn(descriptionEn); this.gradingCriterion = gradingCriterion; } - @Override - public int compareTo(AbstractGradingCriterionPoint abstractGradingCriterionPoint) { - return this.getPoint().compareTo(abstractGradingCriterionPoint.getPoint()); - } - + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public GradingCriterion getGradingCriterion() { return this.gradingCriterion; } @@ -40,9 +42,12 @@ public class GradingCriterionPoint extends AbstractGradingCriterionPoint { this.gradingCriterion = gradingCriterion; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects and Comparable + // ---------------------------------------------------------------------------------- @Override - public String toString() { - return "GradingCriterionPoint(gradingCriterion=" + this.getGradingCriterion() + ")"; + public int compareTo(AbstractGradingCriterionPoint abstractGradingCriterionPoint) { + return this.getPoint().compareTo(abstractGradingCriterionPoint.getPoint()); } @Override @@ -55,13 +60,22 @@ public class GradingCriterionPoint extends AbstractGradingCriterionPoint { && Objects.equals(this.getGradingCriterion(), other.getGradingCriterion()); } + @Override + public int hashCode() { + return Objects.hashCode(this.getGradingCriterion()); + } + + @Override + public String toString() { + return "GradingCriterionPoint(gradingCriterion=" + this.getGradingCriterion() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- @Override protected boolean canEqual(final Object other) { return other instanceof GradingCriterionPoint; } - @Override - public int hashCode() { - return Objects.hashCode(this.getGradingCriterion()); - } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionPointTemplate.java b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionPointTemplate.java index 88708ddf1d..a41785948a 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionPointTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionPointTemplate.java @@ -1,8 +1,10 @@ package se.su.dsv.scipro.report; import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; + import java.util.Objects; @Entity @@ -10,6 +12,7 @@ import java.util.Objects; public class GradingCriterionPointTemplate extends AbstractGradingCriterionPoint { @ManyToOne(optional = false) + @JoinColumn(name = "grading_criterion_template_id", nullable = false) private GradingCriterionTemplate gradingCriterionTemplate; @Override diff --git a/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionTemplate.java b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionTemplate.java index 6feaee5bd8..92ab7539dc 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionTemplate.java @@ -1,18 +1,29 @@ package se.su.dsv.scipro.report; -import jakarta.persistence.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; +import jakarta.persistence.CascadeType; +import jakarta.persistence.DiscriminatorColumn; +import jakarta.persistence.Entity; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; + @Entity -@DiscriminatorColumn(name = "type", length = GradingCriterionTemplate.LENGTH) -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Table(name = "grading_criterion_template") +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "type", length = GradingCriterionTemplate.LENGTH) public abstract class GradingCriterionTemplate extends AbstractGradingCriterion { public static final int LENGTH = 64; + @ManyToOne(optional = false) + @JoinColumn(name = "grading_report_template_id") private GradingReportTemplate gradingReportTemplate; @OneToMany(mappedBy = "gradingCriterionTemplate", orphanRemoval = true, cascade = CascadeType.ALL) diff --git a/core/src/main/java/se/su/dsv/scipro/report/GradingReport.java b/core/src/main/java/se/su/dsv/scipro/report/GradingReport.java index 0c036ede48..6957cae4d5 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/GradingReport.java +++ b/core/src/main/java/se/su/dsv/scipro/report/GradingReport.java @@ -1,11 +1,19 @@ package se.su.dsv.scipro.report; +import jakarta.persistence.Basic; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.Language; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -13,6 +21,7 @@ import java.util.List; import java.util.stream.Collectors; @Entity +@Table(name = "grading_report") public abstract class GradingReport extends Report { public record Grade(String name) { @@ -27,40 +36,51 @@ public abstract class GradingReport extends Report { public enum State { INITIAL, REVIEWING, FINALIZED } + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- + @Basic + @Column(name = "state") @Enumerated(EnumType.STRING) private State state = State.INITIAL; - @ManyToOne(optional = false) - private Project project; - - @OneToMany(mappedBy = "gradingReport", cascade = {CascadeType.ALL}) - private List gradingCriteria = new ArrayList<>(); - @Basic @Column(name = "date_submitted_to_examiner") private Instant dateSubmittedToExaminer; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (grading_report) referencing other + // tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + private Project project; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "grading_report" + // ---------------------------------------------------------------------------------- + @OneToMany(mappedBy = "gradingReport", cascade = {CascadeType.ALL}) + private List gradingCriteria = new ArrayList<>(); + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected GradingReport() { // JPA } - @Override - public void submit() { - super.submit(); - setState(State.FINALIZED); - setDateSubmittedToExaminer(Instant.now()); - } - - public Project getProject() { - return project; - } - GradingReport(Project project) { this.project = project; } - void addCriterion(GradingCriterion criterion) { - gradingCriteria.add(criterion); + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + public State getState() { + return state; + } + + public void setState(final State state) { + this.state = state; } public Instant getDateSubmittedToExaminer(){ @@ -71,12 +91,8 @@ public abstract class GradingReport extends Report { this.dateSubmittedToExaminer = dateSubmittedToExaminer; } - public State getState() { - return state; - } - - public void setState(final State state) { - this.state = state; + public Project getProject() { + return project; } public List getGradingCriteria() { @@ -84,6 +100,21 @@ public abstract class GradingReport extends Report { return Collections.unmodifiableList(gradingCriteria); } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public String toString() { + return "GradingReport(state=" + this.getState() + ", project=" + this.getProject() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + void addCriterion(GradingCriterion criterion) { + gradingCriteria.add(criterion); + } + public String getProjectTitle() { return project.getTitle(); } @@ -112,7 +143,9 @@ public abstract class GradingReport extends Report { } @Override - public String toString() { - return "GradingReport(state=" + this.getState() + ", project=" + this.getProject() + ")"; + public void submit() { + super.submit(); + setState(State.FINALIZED); + setDateSubmittedToExaminer(Instant.now()); } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/GradingReportTemplate.java b/core/src/main/java/se/su/dsv/scipro/report/GradingReportTemplate.java index cc106b6c95..f8b5c9c8c3 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/GradingReportTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/report/GradingReportTemplate.java @@ -1,13 +1,24 @@ package se.su.dsv.scipro.report; +import jakarta.persistence.Basic; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import jakarta.persistence.Temporal; +import jakarta.persistence.TemporalType; import se.su.dsv.scipro.finalseminar.FinalSeminarOpposition; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; - import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; @@ -19,18 +30,16 @@ import java.util.Objects; @Table(name = "grading_report_template") public class GradingReportTemplate extends DomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToOne(optional = false) - private ProjectType projectType; - - @OneToMany(mappedBy = "gradingReportTemplate", cascade = {CascadeType.ALL}, orphanRemoval = true) - private Collection criteria = new HashSet<>(); - - @Temporal(TemporalType.DATE) + @Basic @Column(name = "valid_from") + @Temporal(TemporalType.DATE) private LocalDate validFrom; @Basic @@ -41,10 +50,27 @@ public class GradingReportTemplate extends DomainObject { @Column(name = "failing_grade") private String failingGrade; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (grading_report_template) referencing + // other tables. + // ---------------------------------------------------------------------------------- + @OneToOne(optional = false) + @JoinColumn(name = "project_type_id", referencedColumnName = "id") + private ProjectType projectType; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "grading_report_template" + // ---------------------------------------------------------------------------------- + @OneToMany(mappedBy = "gradingReportTemplate", cascade = {CascadeType.ALL}, orphanRemoval = true) + private Collection criteria = new HashSet<>(); + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "grading_report_template_id") + @JoinColumn(name = "grading_report_template_id", referencedColumnName = "id") private Collection gradeLimits = new ArrayList<>(); + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected GradingReportTemplate() { } @@ -57,43 +83,9 @@ public class GradingReportTemplate extends DomainObject { this.validFrom = validFrom; } - public SupervisorGradingReport createSupervisorReport(Project project, User student) { - if (!this.projectType.equals(project.getProjectType())) { - throw new IllegalArgumentException("Project has a different project class than this template"); - } - return new SupervisorGradingReportFactory().using(criteria).create(project, student); - } - - public OppositionReport createOppositionReport(FinalSeminarOpposition finalSeminarOpposition) { - return new OppositionReport(this, finalSeminarOpposition); - } - - public GradingCriterionTemplate addProjectCriterion(String title, String titleEn, int pointsRequiredToPass, List gradingCriterionPointTemplates) { - return addProjectCriterion(title, titleEn, pointsRequiredToPass, gradingCriterionPointTemplates, null); - } - - public GradingCriterionTemplate addProjectCriterion(String title, String titleEn, int pointsRequiredToPass, List gradingCriterionPointTemplates, AbstractGradingCriterion.Flag flag) { - GradingCriterionTemplate gradingCriterionTemplate = new ProjectGradingCriterionTemplate(this, criteria.size(), title, titleEn, pointsRequiredToPass, gradingCriterionPointTemplates); - gradingCriterionTemplate.setFlag(flag); - criteria.add(gradingCriterionTemplate); - return gradingCriterionTemplate; - } - - public GradingCriterionTemplate addIndividualCriterion(String title, String titleEn, int pointsRequiredToPass, List gradingCriterionPointTemplates) { - return addIndividualCriterion(title, titleEn, pointsRequiredToPass, gradingCriterionPointTemplates, null); - } - - public GradingCriterionTemplate addIndividualCriterion(String title, String titleEn, int pointsRequiredToPass, List gradingCriterionPointTemplates, AbstractGradingCriterion.Flag flag) { - GradingCriterionTemplate gradingCriterionTemplate = new IndividualGradingCriterionTemplate(this, criteria.size(), title, titleEn, pointsRequiredToPass, gradingCriterionPointTemplates); - gradingCriterionTemplate.setFlag(flag); - criteria.add(gradingCriterionTemplate); - return gradingCriterionTemplate; - } - - public Collection getCriteria() { - return criteria; - } - + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; @@ -107,14 +99,6 @@ public class GradingReportTemplate extends DomainObject { this.validFrom = validFrom; } - public ProjectType getProjectType() { - return projectType; - } - - public void setProjectType(ProjectType projectType) { - this.projectType = projectType; - } - public String getNote() { return note; } @@ -131,6 +115,18 @@ public class GradingReportTemplate extends DomainObject { this.failingGrade = failingGrade; } + public ProjectType getProjectType() { + return projectType; + } + + public void setProjectType(ProjectType projectType) { + this.projectType = projectType; + } + + public Collection getCriteria() { + return criteria; + } + public Collection getGradeLimits() { return gradeLimits; } @@ -139,6 +135,9 @@ public class GradingReportTemplate extends DomainObject { this.gradeLimits = gradeLimits; } + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -148,10 +147,6 @@ public class GradingReportTemplate extends DomainObject { && Objects.equals(this.id, other.id); } - protected boolean canEqual(final Object other) { - return other instanceof GradingReportTemplate; - } - @Override public int hashCode() { return Objects.hashCode(this.id); @@ -159,6 +154,56 @@ public class GradingReportTemplate extends DomainObject { @Override public String toString() { - return "GradingReportTemplate(id=" + this.id + ", projectType=" + this.projectType + ", validFrom=" + this.validFrom + ")"; + return "GradingReportTemplate(id=" + this.id + ", projectType=" + this.projectType + ", validFrom=" + + this.validFrom + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + public SupervisorGradingReport createSupervisorReport(Project project, User student) { + if (!this.projectType.equals(project.getProjectType())) { + throw new IllegalArgumentException("Project has a different project class than this template"); + } + return new SupervisorGradingReportFactory().using(criteria).create(project, student); + } + + public OppositionReport createOppositionReport(FinalSeminarOpposition finalSeminarOpposition) { + return new OppositionReport(this, finalSeminarOpposition); + } + + public GradingCriterionTemplate addProjectCriterion(String title, String titleEn, int pointsRequiredToPass, + List gradingCriterionPointTemplates) { + return addProjectCriterion(title, titleEn, pointsRequiredToPass, gradingCriterionPointTemplates, null); + } + + public GradingCriterionTemplate addProjectCriterion(String title, String titleEn, int pointsRequiredToPass, + List gradingCriterionPointTemplates, + AbstractGradingCriterion.Flag flag) { + GradingCriterionTemplate gradingCriterionTemplate = new ProjectGradingCriterionTemplate(this, + criteria.size(), title, titleEn, pointsRequiredToPass, gradingCriterionPointTemplates); + gradingCriterionTemplate.setFlag(flag); + criteria.add(gradingCriterionTemplate); + return gradingCriterionTemplate; + } + + public GradingCriterionTemplate addIndividualCriterion(String title, String titleEn, int pointsRequiredToPass, + List gradingCriterionPointTemplates) { + return addIndividualCriterion(title, titleEn, pointsRequiredToPass, gradingCriterionPointTemplates, null); + } + + public GradingCriterionTemplate addIndividualCriterion(String title, String titleEn, int pointsRequiredToPass, + List gradingCriterionPointTemplates, + AbstractGradingCriterion.Flag flag) { + GradingCriterionTemplate gradingCriterionTemplate = new IndividualGradingCriterionTemplate(this, + criteria.size(), title, titleEn, pointsRequiredToPass, gradingCriterionPointTemplates); + gradingCriterionTemplate.setFlag(flag); + criteria.add(gradingCriterionTemplate); + return gradingCriterionTemplate; + } + + + protected boolean canEqual(final Object other) { + return other instanceof GradingReportTemplate; } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/OppositionReport.java b/core/src/main/java/se/su/dsv/scipro/report/OppositionReport.java index 5775a6db0b..426e393399 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/OppositionReport.java +++ b/core/src/main/java/se/su/dsv/scipro/report/OppositionReport.java @@ -1,10 +1,17 @@ package se.su.dsv.scipro.report; +import jakarta.persistence.Basic; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.finalseminar.FinalSeminarOpposition; import se.su.dsv.scipro.system.Language; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -15,56 +22,57 @@ import java.util.stream.Collectors; @Table(name = "opposition_report") public class OppositionReport extends AttachmentReport { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- + @Basic + @Column(name = "thesis_summary") + private String thesisSummary; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (opposition_report) referencing other + // tables. + // ---------------------------------------------------------------------------------- @OneToOne(optional = false) + @JoinColumn(name = "final_seminar_opposition_id", referencedColumnName = "id") private FinalSeminarOpposition finalSeminarOpposition; + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "opposition_report" + // ---------------------------------------------------------------------------------- @OneToMany(mappedBy = "report", cascade = {CascadeType.ALL}) private List oppositionCriteria = new ArrayList<>(); - @Basic - @Column - private String thesisSummary; - - + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected OppositionReport() { - } - public OppositionReport(GradingReportTemplate gradingReportTemplate, FinalSeminarOpposition finalSeminarOpposition) { + public OppositionReport(GradingReportTemplate gradingReportTemplate, + FinalSeminarOpposition finalSeminarOpposition) { this.finalSeminarOpposition = finalSeminarOpposition; createCriteriaFromTemplate(gradingReportTemplate); } - private void createCriteriaFromTemplate(GradingReportTemplate gradingReportTemplate) { - for (GradingCriterionTemplate template : gradingReportTemplate.getCriteria()) { - if (template.isProjectCriterion()) { - oppositionCriteria.add(new Criterion(this, template)); - } - } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + public String getThesisSummary() { + return this.thesisSummary; } - public List getCriteria() { - oppositionCriteria.sort(new AbstractCriterion.BySortOrderComparator()); - return Collections.unmodifiableList(oppositionCriteria); + public void setThesisSummary(String thesisSummary) { + this.thesisSummary = thesisSummary; } - @Override - public boolean isFinished() { - if (thesisSummaryIsEmpty()) { - return false; - } - for (Criterion criterion : oppositionCriteria) { - if (!criterion.isFilledOut()) { - return false; - } - } - return true; - } - - private boolean thesisSummaryIsEmpty() { - return thesisSummary == null || thesisSummary.isEmpty(); + public FinalSeminarOpposition getFinalSeminarOpposition() { + return this.finalSeminarOpposition; } + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- public User getUser() { return finalSeminarOpposition.getUser(); } @@ -110,15 +118,33 @@ public class OppositionReport extends AttachmentReport { return finalSeminarOpposition.getUser().getLastName(); } - public FinalSeminarOpposition getFinalSeminarOpposition() { - return this.finalSeminarOpposition; + private void createCriteriaFromTemplate(GradingReportTemplate gradingReportTemplate) { + for (GradingCriterionTemplate template : gradingReportTemplate.getCriteria()) { + if (template.isProjectCriterion()) { + oppositionCriteria.add(new Criterion(this, template)); + } + } } - public String getThesisSummary() { - return this.thesisSummary; + public List getCriteria() { + oppositionCriteria.sort(new AbstractCriterion.BySortOrderComparator()); + return Collections.unmodifiableList(oppositionCriteria); } - public void setThesisSummary(String thesisSummary) { - this.thesisSummary = thesisSummary; + @Override + public boolean isFinished() { + if (thesisSummaryIsEmpty()) { + return false; + } + for (Criterion criterion : oppositionCriteria) { + if (!criterion.isFilledOut()) { + return false; + } + } + return true; + } + + private boolean thesisSummaryIsEmpty() { + return thesisSummary == null || thesisSummary.isEmpty(); } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/Report.java b/core/src/main/java/se/su/dsv/scipro/report/Report.java index dd1437fc18..da88711b3b 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/Report.java +++ b/core/src/main/java/se/su/dsv/scipro/report/Report.java @@ -1,48 +1,36 @@ package se.su.dsv.scipro.report; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.Table; import se.su.dsv.scipro.system.DomainObject; -import jakarta.persistence.*; import java.util.Objects; @Entity @Table(name = "report") @Inheritance(strategy = InheritanceType.JOINED) public abstract class Report extends DomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Basic(optional = false) + @Column(name = "submitted") private boolean submitted = false; - public abstract boolean isFinished(); - - public void submit() { - if (!isFinished()) { - throw new IllegalStateException("Report is not finished: you need to score and give feedback to every criteria"); - } - submitted = true; - } - - @Override - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof Report)) return false; - final Report other = (Report) o; - return other.canEqual(this) - && Objects.equals(this.id, other.id); - } - - protected boolean canEqual(final Object other) { - return other instanceof Report; - } - - @Override - public int hashCode() { - return Objects.hashCode(this.id); - } - + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; @@ -55,4 +43,37 @@ public abstract class Report extends DomainObject { public void setSubmitted(boolean submitted) { this.submitted = submitted; } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- + @Override + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof Report)) return false; + final Report other = (Report) o; + return other.canEqual(this) + && Objects.equals(this.id, other.id); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.id); + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof Report; + } + + public abstract boolean isFinished(); + + public void submit() { + if (!isFinished()) { + throw new IllegalStateException("Report is not finished: you need to score and give feedback to every criteria"); + } + submitted = true; + } } diff --git a/core/src/main/java/se/su/dsv/scipro/report/SupervisorGradingReport.java b/core/src/main/java/se/su/dsv/scipro/report/SupervisorGradingReport.java index b3e682dfba..59b4bca6b8 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/SupervisorGradingReport.java +++ b/core/src/main/java/se/su/dsv/scipro/report/SupervisorGradingReport.java @@ -1,26 +1,24 @@ package se.su.dsv.scipro.report; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import se.su.dsv.scipro.project.Project; -import se.su.dsv.scipro.system.User; - import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import se.su.dsv.scipro.project.Project; +import se.su.dsv.scipro.system.User; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @Entity +@Table(name = "supervisor_grading_report") public class SupervisorGradingReport extends GradingReport { - - private static final Logger LOG = LoggerFactory.getLogger(SupervisorGradingReport.class); - - @ManyToOne(optional = false) - private User user; - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Basic @Column(name = "rejection_comment") private String rejectionComment; @@ -33,6 +31,17 @@ public class SupervisorGradingReport extends GradingReport { @Column(name = "motivation") private String motivation; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (grading_criterion) referencing other + // tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + @JoinColumn(name = "user_id", referencedColumnName = "id") + private User user; + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected SupervisorGradingReport() { // JPA } @@ -42,6 +51,40 @@ public class SupervisorGradingReport extends GradingReport { this.user = user; } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + public User getUser() { + return this.user; + } + + public String getRejectionComment() { + return rejectionComment; + } + + public void setRejectionComment(String rejectionComment) { + this.rejectionComment = rejectionComment; + } + + public String getRejectionCommentFeedback() { + return rejectionCommentFeedback; + } + + public void setRejectionCommentFeedback(String rejectionCommentFeedback) { + this.rejectionCommentFeedback = rejectionCommentFeedback; + } + + public String getMotivation() { + return motivation; + } + + public void setMotivation(String motivation) { + this.motivation = motivation; + } + + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- public List getProjectCriteria() { List result = new ArrayList<>(); for (GradingCriterion criterion : getGradingCriteria()) { @@ -82,34 +125,6 @@ public class SupervisorGradingReport extends GradingReport { return true; } - public User getUser() { - return this.user; - } - - public String getRejectionComment() { - return rejectionComment; - } - - public void setRejectionComment(String rejectionComment) { - this.rejectionComment = rejectionComment; - } - - public String getRejectionCommentFeedback() { - return rejectionCommentFeedback; - } - - public void setRejectionCommentFeedback(String rejectionCommentFeedback) { - this.rejectionCommentFeedback = rejectionCommentFeedback; - } - - public String getMotivation() { - return motivation; - } - - public void setMotivation(String motivation) { - this.motivation = motivation; - } - public boolean hasProvidedOverallMotivation() { return getMotivation() != null && !getMotivation().isBlank(); } diff --git a/core/src/main/java/se/su/dsv/scipro/reviewing/Decision.java b/core/src/main/java/se/su/dsv/scipro/reviewing/Decision.java index cc255a893e..6d3fb25f16 100644 --- a/core/src/main/java/se/su/dsv/scipro/reviewing/Decision.java +++ b/core/src/main/java/se/su/dsv/scipro/reviewing/Decision.java @@ -20,51 +20,73 @@ import se.su.dsv.scipro.system.User; import java.time.Instant; import java.time.LocalDate; -import java.util.*; +import java.util.Date; +import java.util.Optional; @Entity -@Table(name = "Decision") +@Table(name = "decision") public class Decision { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic + @Column(name = "status") @Enumerated(EnumType.STRING) private Status status = Status.UNDECIDED; - @OneToOne(optional = false) - @JoinColumn(name = "thesis_reference_id") - private FileReference thesis; - @Basic + @Column(name = "reason") private String reason; @Basic + @Column(name = "comment") private String comment; - @OneToOne(optional = true) - @JoinColumn(name = "attachment_reference_id") - private FileReference attachment; - + @Basic + @Column(name = "requested_date") @Temporal(TemporalType.TIMESTAMP) private Date requested; - @Temporal(TemporalType.TIMESTAMP) - private Date deadline; - + @Basic + @Column(name = "decision_date") @Temporal(TemporalType.TIMESTAMP) private Date decisionDate; - @ManyToOne(optional = false) - private ReviewerApproval reviewerApproval; - - @ManyToOne - @JoinColumn(name = "assigned_reviewer_id") - private User assignedReviewer; + @Basic + @Column(name = "deadline") + @Temporal(TemporalType.TIMESTAMP) + private Date deadline; + @Basic @Column(name = "assigned_reviewer_date") private LocalDate reviewerAssignedAt; + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (decision) referencing other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne + @JoinColumn(name = "assigned_reviewer_id", referencedColumnName = "id") + private User assignedReviewer; + + @OneToOne(optional = true) + @JoinColumn(name = "attachment_reference_id", referencedColumnName = "id") + private FileReference attachment; + + @ManyToOne(optional = false) + @JoinColumn(name = "reviewer_approval_id", referencedColumnName = "id") + private ReviewerApproval reviewerApproval; + + @OneToOne(optional = false) + @JoinColumn(name = "thesis_reference_id", referencedColumnName = "id") + private FileReference thesis; + + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected Decision() {} // JPA Decision(ReviewerApproval reviewerApproval, final FileReference thesis, final String comment, final Date deadline) { @@ -79,6 +101,9 @@ public class Decision { this.comment = comment; } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public Long getId() { return id; } @@ -87,14 +112,6 @@ public class Decision { this.id = id; } - public FileReference getThesis() { - return thesis; - } - - public ReviewerApproval getReviewerApproval() { - return reviewerApproval; - } - public Status getStatus() { return status; } @@ -107,10 +124,6 @@ public class Decision { return comment; } - public Optional getAttachment() { - return Optional.ofNullable(attachment); - } - public Date getRequested() { return requested; } @@ -127,14 +140,6 @@ public class Decision { this.deadline = deadline; } - public User getAssignedReviewer() { - return assignedReviewer; - } - - public void setAssignedReviewer(User assignedReviewer) { - this.assignedReviewer = assignedReviewer; - } - public LocalDate getReviewerAssignedAt() { return reviewerAssignedAt; } @@ -143,6 +148,29 @@ public class Decision { this.reviewerAssignedAt = reviewerAssignedAt; } + public User getAssignedReviewer() { + return assignedReviewer; + } + + public void setAssignedReviewer(User assignedReviewer) { + this.assignedReviewer = assignedReviewer; + } + + public Optional getAttachment() { + return Optional.ofNullable(attachment); + } + + public ReviewerApproval getReviewerApproval() { + return reviewerApproval; + } + + public FileReference getThesis() { + return thesis; + } + + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- void approve(final String reason, final Optional attachment) { decide(Status.APPROVED, reason, attachment); } diff --git a/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerApproval.java b/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerApproval.java index 25c63338aa..cdad680797 100644 --- a/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerApproval.java +++ b/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerApproval.java @@ -1,6 +1,8 @@ package se.su.dsv.scipro.reviewing; import jakarta.persistence.GenerationType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Table; import se.su.dsv.scipro.file.FileReference; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; @@ -13,31 +15,61 @@ import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import jakarta.persistence.OrderBy; -import java.util.*; + +import java.util.Collections; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; @Entity +@Table(name = "reviewer_approval") @DiscriminatorColumn(name = "type", length = 64) public abstract class ReviewerApproval extends DomainObject { - @OneToOne(optional = false) - protected Project project; - - @OneToMany(mappedBy = "reviewerApproval", cascade = CascadeType.ALL) - @OrderBy("requested desc") - protected List decisions = new LinkedList<>(); - + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - public abstract Step getStep(); + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (reviewer_approval) referencing other + // tables. + // ---------------------------------------------------------------------------------- + @OneToOne(optional = false) + @JoinColumn(name = "project_id", referencedColumnName = "id") + protected Project project; - public FileReference getCurrentThesis() { - return getCurrentDecision().getThesis(); + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "reviewer_approval" + // ---------------------------------------------------------------------------------- + @OneToMany(mappedBy = "reviewerApproval", cascade = CascadeType.ALL) + @OrderBy("requested desc") + protected List decisions = new LinkedList<>(); + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return this.id; } public Project getProject(){return this.project;} + // ---------------------------------------------------------------------------------- + // Other methods + // ---------------------------------------------------------------------------------- + public abstract Step getStep(); + public Decision getCurrentDecision() { + return decisions.get(0); + } + + public FileReference getCurrentThesis() { + return getCurrentDecision().getThesis(); + } public Status getCurrentStatus() { return getCurrentDecision().getStatus(); @@ -63,10 +95,6 @@ public abstract class ReviewerApproval extends DomainObject { getCurrentDecision().reject(reason, attachment); } - public Decision getCurrentDecision() { - return decisions.get(0); - } - public void addNewThesis(final FileReference thesis, final String comment, final Date deadline) { if (getCurrentStatus() != Status.REJECTED) { throw new IllegalStateException(); @@ -86,17 +114,15 @@ public abstract class ReviewerApproval extends DomainObject { return getCurrentStatus() == Status.APPROVED; } - @Override - public Long getId() { - return this.id; + public Date getCurrentDeadline() { + return getCurrentDecision().getDeadline(); } + // ---------------------------------------------------------------------------------- + // Nested types. + // ---------------------------------------------------------------------------------- public enum Step { ROUGH_DRAFT_APPROVAL, FINAL_SEMINAR_APPROVAL } - - public Date getCurrentDeadline() { - return getCurrentDecision().getDeadline(); - } } diff --git a/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerDeadlineSettings.java b/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerDeadlineSettings.java index 3b200eac44..044ada8fb5 100644 --- a/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerDeadlineSettings.java +++ b/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerDeadlineSettings.java @@ -13,13 +13,13 @@ public class ReviewerDeadlineSettings extends DomainObject { @Id private Long id = null; - @Basic(optional = false) + @Column(name = "rough_draft_approval", nullable = false) private int roughDraftApproval = 5; - @Basic(optional = false) + @Column(name = "final_seminar_approval", nullable = false) private int finalSeminarApproval = 2; - @Basic(optional = false) + @Column(name = "final_grading", nullable = false) private int finalGrading = 5; public ReviewerDeadlineSettings() { diff --git a/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerTarget.java b/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerTarget.java index 4a8b145f2e..29803d920f 100644 --- a/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerTarget.java +++ b/core/src/main/java/se/su/dsv/scipro/reviewing/ReviewerTarget.java @@ -1,5 +1,6 @@ package se.su.dsv.scipro.reviewing; +import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -10,7 +11,6 @@ import jakarta.persistence.Table; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import java.time.LocalDate; import java.util.Objects; @Entity @@ -20,22 +20,26 @@ public class ReviewerTarget extends DomainObject { @GeneratedValue(strategy = jakarta.persistence.GenerationType.IDENTITY) private Long id; - @ManyToOne(optional = false) - @JoinColumn(name = "reviewer_id", nullable = false) - private User reviewer; - + @Basic @Column(name = "year", nullable = false) private int year; + @Basic @Column(name = "spring", nullable = false) private int spring; + @Basic @Column(name = "autumn", nullable = false) private int autumn; + @Basic @Column(name = "note") private String note; + @ManyToOne(optional = false) + @JoinColumn(name = "reviewer_user_id", referencedColumnName = "id", nullable = false) + private User reviewer; + @Override public Long getId() { return id; diff --git a/core/src/main/java/se/su/dsv/scipro/settings/dataobjects/UserProfile.java b/core/src/main/java/se/su/dsv/scipro/settings/dataobjects/UserProfile.java index ac863a2afa..e88c4b289b 100644 --- a/core/src/main/java/se/su/dsv/scipro/settings/dataobjects/UserProfile.java +++ b/core/src/main/java/se/su/dsv/scipro/settings/dataobjects/UserProfile.java @@ -1,5 +1,26 @@ package se.su.dsv.scipro.settings.dataobjects; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.Objects; + +import jakarta.persistence.Basic; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + import se.su.dsv.scipro.project.ProjectStatus; import se.su.dsv.scipro.project.ProjectTeamMemberRoles; import se.su.dsv.scipro.security.auth.roles.Roles; @@ -7,12 +28,6 @@ import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EnumSet; -import java.util.Objects; - @Entity @Table(name = "user_profile") public class UserProfile extends DomainObject { @@ -24,40 +39,46 @@ public class UserProfile extends DomainObject { @OneToOne(optional = false) private User user; - @Basic(optional = true) - private String skypeId; - - @Basic(optional = true) - private String phoneNumber; - - @Basic(optional = true) + @Column(name = "other_info", nullable = true) private String otherInfo; - @Basic(optional = false) + @Column(name = "phone_number", nullable = true) + private String phoneNumber; + + @Column(name = "skype_id", nullable = true) + private String skypeId; + + @Column(name = "mail_compilation", nullable = false) private boolean mailCompilation = false; + @Column(name = "default_supervisor_filter", nullable = false) + private boolean defaultSupervisorFilter = true; + + @Enumerated(EnumType.STRING) + @Column(name = "selected_role") + private Roles selectedRole; + @ElementCollection @Enumerated(EnumType.STRING) + @CollectionTable(name = "user_profile_default_project_status_filter", + joinColumns = @JoinColumn(name = "user_profile_id", referencedColumnName = "id")) + @Column(name = "default_project_status_filter") private Collection defaultProjectStatusFilter = EnumSet.of(ProjectStatus.ACTIVE); @ElementCollection @Enumerated(EnumType.STRING) + @CollectionTable(name = "user_profile_default_project_team_member_roles_filter", + joinColumns = @JoinColumn(name = "user_profile_id", referencedColumnName = "id")) + @Column(name = "default_project_team_member_roles_filter") private Collection defaultProjectTeamMemberRolesFilter = EnumSet.of(ProjectTeamMemberRoles.CO_SUPERVISOR); - @Basic(optional = false) - private boolean defaultSupervisorFilter = true; - @ManyToMany - @JoinTable( - name = "user_profile_ProjectType", - joinColumns = {@JoinColumn(name = "user_profile_id")} + @JoinTable(name = "user_profile_project_type", + joinColumns = @JoinColumn(name = "user_profile_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "project_type_id", referencedColumnName = "id") ) private Collection defaultProjectTypeFilter = new ArrayList<>(); - @Basic - @Enumerated(EnumType.STRING) - private Roles selectedRole; - @Basic @Enumerated(EnumType.STRING) @Column(name = "supervisor_project_note_display") diff --git a/core/src/main/java/se/su/dsv/scipro/survey/Question.java b/core/src/main/java/se/su/dsv/scipro/survey/Question.java index 4097ad1283..4c2d6e4a73 100644 --- a/core/src/main/java/se/su/dsv/scipro/survey/Question.java +++ b/core/src/main/java/se/su/dsv/scipro/survey/Question.java @@ -1,11 +1,23 @@ package se.su.dsv.scipro.survey; -import jakarta.persistence.*; +import jakarta.persistence.Basic; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Table; + import java.io.Serializable; import java.util.LinkedList; import java.util.List; @Entity +@Table(name = "question") public class Question implements Serializable { public enum Type { TEXT, SINGLE_CHOICE, MULTIPLE_CHOICE, GROUP_HEADING } @@ -20,6 +32,9 @@ public class Question implements Serializable { private String text; @ElementCollection(fetch = FetchType.EAGER) + @CollectionTable(name = "question_choices", + joinColumns = @JoinColumn(name = "question_id", referencedColumnName = "id")) + @Column(name = "choices") private List choices = new LinkedList<>(); private Type type = Type.TEXT; diff --git a/core/src/main/java/se/su/dsv/scipro/survey/Survey.java b/core/src/main/java/se/su/dsv/scipro/survey/Survey.java index 01b44b7e1d..9c9621ec02 100644 --- a/core/src/main/java/se/su/dsv/scipro/survey/Survey.java +++ b/core/src/main/java/se/su/dsv/scipro/survey/Survey.java @@ -1,14 +1,23 @@ package se.su.dsv.scipro.survey; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.io.Serializable; import java.util.LinkedList; import java.util.List; @Entity +@Table(name = "survey") public class Survey implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/core/src/main/java/se/su/dsv/scipro/survey/SurveyAnswer.java b/core/src/main/java/se/su/dsv/scipro/survey/SurveyAnswer.java index 0deab2b69b..f8d94e7ab9 100644 --- a/core/src/main/java/se/su/dsv/scipro/survey/SurveyAnswer.java +++ b/core/src/main/java/se/su/dsv/scipro/survey/SurveyAnswer.java @@ -6,7 +6,7 @@ import java.util.Set; import java.util.TreeSet; @Entity -@Table +@Table(name = "survey_answer") public class SurveyAnswer implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -21,6 +21,9 @@ public class SurveyAnswer implements Serializable { private String answer; @ElementCollection(fetch = FetchType.EAGER) + @CollectionTable(name = "survey_answer_multiple_answers", + joinColumns = @JoinColumn(name = "survey_answer_id", referencedColumnName = "id")) + @Column(name = "multiple_answers") private Set multipleAnswers = new TreeSet<>(); public Survey getSurvey() { diff --git a/core/src/main/java/se/su/dsv/scipro/system/DomainObject.java b/core/src/main/java/se/su/dsv/scipro/system/DomainObject.java index bb414d678c..ebcdbb5627 100755 --- a/core/src/main/java/se/su/dsv/scipro/system/DomainObject.java +++ b/core/src/main/java/se/su/dsv/scipro/system/DomainObject.java @@ -8,10 +8,10 @@ import java.util.Objects; @MappedSuperclass public abstract class DomainObject implements Serializable { - @Basic(optional=false) + @Column(name = "date_created", nullable = false) private Date dateCreated = new Date(); - @Basic(optional = false) + @Column(name = "last_modified", nullable = false) private Date lastModified = new Date(); @Version diff --git a/core/src/main/java/se/su/dsv/scipro/system/Event.java b/core/src/main/java/se/su/dsv/scipro/system/Event.java index 76abc8f2bb..be417ccb9a 100644 --- a/core/src/main/java/se/su/dsv/scipro/system/Event.java +++ b/core/src/main/java/se/su/dsv/scipro/system/Event.java @@ -1,22 +1,36 @@ package se.su.dsv.scipro.system; import jakarta.persistence.Basic; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import jakarta.persistence.Table; + import java.io.Serializable; import java.util.Objects; @Entity +@Table(name = "event") public class Event implements Serializable { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id private String name; @Basic + @Column(name = "description") private String description; + // ---------------------------------------------------------------------------------- + // Constructor + // ---------------------------------------------------------------------------------- protected Event() { } + // ---------------------------------------------------------------------------------- + // Properties (Getters) + // ---------------------------------------------------------------------------------- public String getName() { return this.name; } @@ -25,6 +39,13 @@ public class Event implements Serializable { return this.description; } + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof Event; + } + @Override public boolean equals(final Object o) { if (o == this) return true; @@ -34,10 +55,6 @@ public class Event implements Serializable { && Objects.equals(this.getName(), other.getName()); } - protected boolean canEqual(final Object other) { - return other instanceof Event; - } - @Override public int hashCode() { return Objects.hashCode(this.getName()); @@ -45,6 +62,7 @@ public class Event implements Serializable { @Override public String toString() { - return "Event(name=" + this.getName() + ", description=" + this.getDescription() + ")"; + return "Event(name=" + this.getName() + ", description=" + + this.getDescription() + ")"; } } diff --git a/core/src/main/java/se/su/dsv/scipro/system/ExternalResource.java b/core/src/main/java/se/su/dsv/scipro/system/ExternalResource.java index 852eac7bbb..008e47babe 100644 --- a/core/src/main/java/se/su/dsv/scipro/system/ExternalResource.java +++ b/core/src/main/java/se/su/dsv/scipro/system/ExternalResource.java @@ -1,9 +1,18 @@ package se.su.dsv.scipro.system; -import jakarta.persistence.*; +import jakarta.persistence.Basic; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + import java.util.Objects; @Entity +@Table(name = "external_resource") public class ExternalResource { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -16,6 +25,7 @@ public class ExternalResource { private String url; @ManyToOne(optional = false) + @JoinColumn(name = "project_type_id") private ProjectType relevantFor; public ExternalResource() {} // JPA diff --git a/core/src/main/java/se/su/dsv/scipro/system/FooterLink.java b/core/src/main/java/se/su/dsv/scipro/system/FooterLink.java index 7676611142..68a84f622f 100644 --- a/core/src/main/java/se/su/dsv/scipro/system/FooterLink.java +++ b/core/src/main/java/se/su/dsv/scipro/system/FooterLink.java @@ -13,6 +13,7 @@ public class FooterLink extends DomainObject { private Long id; @Enumerated(EnumType.STRING) + @Column(name = "footer_column") private FooterColumn footerColumn; @Basic(optional = false) diff --git a/core/src/main/java/se/su/dsv/scipro/system/Password.java b/core/src/main/java/se/su/dsv/scipro/system/Password.java index 32dd434660..8cc600ed24 100755 --- a/core/src/main/java/se/su/dsv/scipro/system/Password.java +++ b/core/src/main/java/se/su/dsv/scipro/system/Password.java @@ -1,11 +1,18 @@ package se.su.dsv.scipro.system; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + import java.util.Arrays; import java.util.Objects; @Entity -@Table +@Table(name = "password") public class Password extends LazyDeletableDomainObject { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/core/src/main/java/se/su/dsv/scipro/system/Program.java b/core/src/main/java/se/su/dsv/scipro/system/Program.java index 2c23655ccc..f2aba4587d 100644 --- a/core/src/main/java/se/su/dsv/scipro/system/Program.java +++ b/core/src/main/java/se/su/dsv/scipro/system/Program.java @@ -1,10 +1,16 @@ package se.su.dsv.scipro.system; -import jakarta.persistence.*; import java.util.Objects; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + @Entity -@Table(name = "Program") +@Table(name = "program") public class Program extends DomainObject { @Id @@ -12,13 +18,13 @@ public class Program extends DomainObject { @Column(name = "id") private Long id; - @Column(name = "externalId") + @Column(name = "external_id") private Integer externalId; - @Column(name = "name") + @Column(name = "name_sv") private String name; - @Column(name = "nameEn", nullable = true) + @Column(name = "name_en", nullable = true) private String nameEn; @Column(name = "code") diff --git a/core/src/main/java/se/su/dsv/scipro/system/ProjectType.java b/core/src/main/java/se/su/dsv/scipro/system/ProjectType.java index 0d3bd00f2c..b3f8849870 100644 --- a/core/src/main/java/se/su/dsv/scipro/system/ProjectType.java +++ b/core/src/main/java/se/su/dsv/scipro/system/ProjectType.java @@ -1,12 +1,29 @@ package se.su.dsv.scipro.system; -import jakarta.persistence.*; import java.util.EnumSet; import java.util.Objects; import java.util.Set; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.Lob; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + @Entity @Cacheable(true) +@Table(name = "project_type") public class ProjectType extends LazyDeletableDomainObject { public static final DegreeType MASTER = DegreeType.MASTER; public static final DegreeType BACHELOR = DegreeType.BACHELOR; @@ -26,7 +43,7 @@ public class ProjectType extends LazyDeletableDomainObject { private ProjectTypeSettings projectTypeSettings = new ProjectTypeSettings(this); @Enumerated(EnumType.STRING) - @Column(nullable = false) + @Column(name = "degree_type", nullable = false) private DegreeType degreeType = DegreeType.NONE; @Lob @@ -34,7 +51,9 @@ public class ProjectType extends LazyDeletableDomainObject { @ElementCollection @Enumerated(EnumType.STRING) - @JoinTable(name = "project_type_project_modules") + @CollectionTable(name = "project_type_project_module", + joinColumns = @JoinColumn(name = "project_type_id", referencedColumnName = "id")) + @Column(name = "project_module") private Set projectModules = EnumSet.allOf(ProjectModule.class); @Basic(optional = false) diff --git a/core/src/main/java/se/su/dsv/scipro/system/ProjectTypeSettings.java b/core/src/main/java/se/su/dsv/scipro/system/ProjectTypeSettings.java index f83d626f1b..2c64d6629d 100755 --- a/core/src/main/java/se/su/dsv/scipro/system/ProjectTypeSettings.java +++ b/core/src/main/java/se/su/dsv/scipro/system/ProjectTypeSettings.java @@ -1,68 +1,84 @@ package se.su.dsv.scipro.system; -import jakarta.persistence.*; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + import java.util.Objects; @Entity -@Table(name="project_type_settings") @Cacheable(true) +@Table(name="project_type_settings") public class ProjectTypeSettings extends DomainObject { - public ProjectTypeSettings(){} - - public ProjectTypeSettings(ProjectType projectType){ - this.projectType = projectType; - } + public static final int DEFAULT_NUM_DAYS_BETWEEN_REVIEWS_ON_SAME_PROJECT = 7; + public static final int DEFAULT_NUM_DAYS_TO_SUBMIT_PEER_REVIEW = 3; + public static final int DEFAULT_NUM_DAYS_BEFORE_CANCELLED_PEERS = 90; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @OneToOne(optional = false) + @JoinColumn(name = "project_type_id") private ProjectType projectType; - @Basic(optional=false) - private int minAuthors = 1; - @Basic(optional=false) - private int maxAuthors = 2; - - @Basic(optional=false) - private int maxFinalSeminarActiveParticipation; - @Basic(optional=false) - private int maxOpponentsOnFinalSeminar; - @Basic(optional=false) - private int minFinalSeminarActiveParticipation; - @Basic(optional=false) - private int minOpponentsOnFinalSeminar; - - private int minimumOppositionsToBeGraded = 0; - private int minimumActiveParticipationsToBeGraded = 0; - - public static final int DEFAULT_NUM_DAYS_BETWEEN_REVIEWS_ON_SAME_PROJECT = 7; - public static final int DEFAULT_NUM_DAYS_TO_SUBMIT_PEER_REVIEW = 3; - public static final int DEFAULT_NUM_DAYS_BEFORE_CANCELLED_PEERS = 90; - /* * Defines the time span between reviews on the same project */ - @Basic(optional = false) + @Column(name = "num_days_between_peer_reviews_on_same_project", nullable = false) private int numDaysBetweenPeerReviewsOnSameProject = DEFAULT_NUM_DAYS_BETWEEN_REVIEWS_ON_SAME_PROJECT; - + /* * Defines the number of days between accepting a review and the deadline for review submission */ - @Basic(optional = false) + @Column(name = "num_days_to_submit_peer_review", nullable = false) private int numDaysToSubmitPeerReview = DEFAULT_NUM_DAYS_TO_SUBMIT_PEER_REVIEW; /* * Defines the number of days between accepting a review and the deadline for review submission */ - @Basic(optional = false) + @Column(name = "num_days_before_peer_gets_cancelled", nullable = false) private int numDaysBeforePeerGetsCancelled = DEFAULT_NUM_DAYS_BEFORE_CANCELLED_PEERS; - @Basic + @Column(name = "min_authors", nullable = false) + private int minAuthors = 1; + + @Column(name = "max_authors", nullable = false) + private int maxAuthors = 2; + + @Column(name = "max_final_seminar_active_participation", nullable = false) + private int maxFinalSeminarActiveParticipation; + + @Column(name = "max_opponents_on_final_seminar", nullable = false) + private int maxOpponentsOnFinalSeminar; + + @Column(name = "min_final_seminar_active_participation", nullable = false) + private int minFinalSeminarActiveParticipation; + + @Column(name = "min_opponents_on_final_seminar", nullable = false) + private int minOpponentsOnFinalSeminar; + + @Column(name = "min_oppositions_to_be_graded") + private int minOppositionsToBeGraded = 0; + + @Column(name = "min_active_participations_to_be_graded") + private int minActiveParticipationsToBeGraded = 0; + @Column(name = "review_process_information_url_for_supervisor") private String reviewProcessInformationUrl; + public ProjectTypeSettings(){} + + public ProjectTypeSettings(ProjectType projectType){ + this.projectType = projectType; + } + @Override public Long getId() { return this.id; @@ -152,20 +168,20 @@ public class ProjectTypeSettings extends DomainObject { this.numDaysBeforePeerGetsCancelled = numDaysBeforePeerGetsCancelled; } - public int getMinimumOppositionsToBeGraded() { - return minimumOppositionsToBeGraded; + public int getMinOppositionsToBeGraded() { + return minOppositionsToBeGraded; } - public void setMinimumOppositionsToBeGraded(int minimumOppositionsToBeGraded) { - this.minimumOppositionsToBeGraded = minimumOppositionsToBeGraded; + public void setMinOppositionsToBeGraded(int minimumOppositionsToBeGraded) { + this.minOppositionsToBeGraded = minimumOppositionsToBeGraded; } - public int getMinimumActiveParticipationsToBeGraded() { - return minimumActiveParticipationsToBeGraded; + public int getMinActiveParticipationsToBeGraded() { + return minActiveParticipationsToBeGraded; } - public void setMinimumActiveParticipationsToBeGraded(int minimumActiveParticipationsToBeGraded) { - this.minimumActiveParticipationsToBeGraded = minimumActiveParticipationsToBeGraded; + public void setMinActiveParticipationsToBeGraded(int minimumActiveParticipationsToBeGraded) { + this.minActiveParticipationsToBeGraded = minimumActiveParticipationsToBeGraded; } public String getReviewProcessInformationUrl() { diff --git a/core/src/main/java/se/su/dsv/scipro/system/ResearchArea.java b/core/src/main/java/se/su/dsv/scipro/system/ResearchArea.java index 11a8bb041f..01e994645b 100755 --- a/core/src/main/java/se/su/dsv/scipro/system/ResearchArea.java +++ b/core/src/main/java/se/su/dsv/scipro/system/ResearchArea.java @@ -1,14 +1,22 @@ package se.su.dsv.scipro.system; -import jakarta.persistence.*; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + import java.util.Objects; @Entity -@Table(name = "researcharea") +@Table(name = "research_area") @Cacheable(true) public class ResearchArea extends LazyDeletableDomainObject { - public static final int STRING_MAX_LENGTH = 255; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/core/src/main/java/se/su/dsv/scipro/system/Unit.java b/core/src/main/java/se/su/dsv/scipro/system/Unit.java index acc2b2793c..404baee063 100755 --- a/core/src/main/java/se/su/dsv/scipro/system/Unit.java +++ b/core/src/main/java/se/su/dsv/scipro/system/Unit.java @@ -1,6 +1,13 @@ package se.su.dsv.scipro.system; -import jakarta.persistence.*; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + import java.util.Objects; @Entity @@ -17,11 +24,10 @@ public class Unit extends DomainObject { @Column(unique = true) private Integer identifier; - @Column(length = STRING_MAX_LENGTH) - @Basic(optional = false) + @Column(nullable = false, length = STRING_MAX_LENGTH) private String title; - @Basic(optional = true) + @Column(name = "match_responsible", nullable = true) private String matchResponsible; public String getMatchResponsible() { diff --git a/core/src/main/java/se/su/dsv/scipro/system/User.java b/core/src/main/java/se/su/dsv/scipro/system/User.java index 1ee2da3877..9addbde052 100755 --- a/core/src/main/java/se/su/dsv/scipro/system/User.java +++ b/core/src/main/java/se/su/dsv/scipro/system/User.java @@ -1,10 +1,32 @@ package se.su.dsv.scipro.system; -import se.su.dsv.scipro.security.auth.roles.Roles; +import jakarta.persistence.Basic; +import jakarta.persistence.Cacheable; +import jakarta.persistence.CascadeType; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; -import jakarta.persistence.*; import java.io.Serializable; -import java.util.*; +import java.util.Comparator; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import se.su.dsv.scipro.security.auth.roles.Roles; @Entity @Table(name = "user") @@ -18,9 +40,10 @@ public class User extends LazyDeletableDomainObject { @Column(unique = true) private Integer identifier; - @Basic(optional = false) + @Column(name = "first_name", nullable = false) private String firstName; - @Basic(optional = false) + + @Column(name = "last_name", nullable = false) private String lastName; // Mapped to a generated column to allow sorting UserColumn in DataTables @@ -35,14 +58,15 @@ public class User extends LazyDeletableDomainObject { // If you wish to test specific sort orders then add specific methods that sort // by firstName, lastName instead. @SuppressWarnings("unused") - @Basic - @Column(insertable = false, updatable = false) + @Column(name = "full_name", insertable = false, updatable = false) private String fullName; - @Basic(optional = false) + @Column(name = "email_address", nullable = false) private String emailAddress; + @Basic(optional = false) private boolean deceased = false; + @Basic(optional = false) @Column(name = "active_as_supervisor") private boolean activeAsSupervisor = false; @@ -64,20 +88,22 @@ public class User extends LazyDeletableDomainObject { private Set programs = new HashSet<>(); @ElementCollection - @CollectionTable(name = "user_languages") + @CollectionTable(name = "user_language") @Column(name = "language") @Enumerated(EnumType.STRING) private Set languages = EnumSet.noneOf(Language.class); @ManyToMany - @JoinTable(name = "user_research_area", inverseJoinColumns = @JoinColumn(name = "research_area_id")) + @JoinTable(name = "user_research_area", + joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "research_area_id", referencedColumnName = "id")) private Set researchAreas = new HashSet<>(); @OneToOne(optional = true) private Unit unit; - @Basic @Enumerated(EnumType.STRING) + @Column(name = "degree_type") private DegreeType degreeType = ProjectType.UNKNOWN; public Unit getUnit() { diff --git a/core/src/main/java/se/su/dsv/scipro/system/Username.java b/core/src/main/java/se/su/dsv/scipro/system/Username.java index e4836b5070..5da461d2b6 100755 --- a/core/src/main/java/se/su/dsv/scipro/system/Username.java +++ b/core/src/main/java/se/su/dsv/scipro/system/Username.java @@ -1,17 +1,26 @@ package se.su.dsv.scipro.system; -import jakarta.persistence.*; +import jakarta.persistence.Cacheable; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; + import java.util.Objects; @Entity +@Table(name="username", uniqueConstraints={@UniqueConstraint(name = "uk_username", columnNames={"username"})}) @Cacheable(true) -@Table(name="username", uniqueConstraints={@UniqueConstraint(columnNames={"username"})}) public class Username extends DomainObject { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Basic(optional=false) + @Column(name = "username", nullable = false) private String username; @ManyToOne(optional=false) diff --git a/core/src/main/java/se/su/dsv/scipro/thesislink/ExternalLink.java b/core/src/main/java/se/su/dsv/scipro/thesislink/ExternalLink.java index aeeff1631a..ee96eb8884 100644 --- a/core/src/main/java/se/su/dsv/scipro/thesislink/ExternalLink.java +++ b/core/src/main/java/se/su/dsv/scipro/thesislink/ExternalLink.java @@ -1,84 +1,103 @@ package se.su.dsv.scipro.thesislink; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; -import jakarta.persistence.*; import java.util.Objects; @Entity -@Table(name = "externallink") +@Table(name = "external_link") public class ExternalLink extends DomainObject { public static final int MAX_CHARS = 255; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne(optional = false) - private Project project; - - @Column(nullable = false, length = MAX_CHARS) - private String url = ""; - - @ManyToOne(optional = false) - private User user; - - @Column(nullable = true, length = MAX_CHARS) - private String description = ""; - public static IProject builder() { return new Builder(); } + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Basic + @Column(name = "url", nullable = false, length = MAX_CHARS) + private String url = ""; + + @Column(name = "description", nullable = true, length = MAX_CHARS) + private String description = ""; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (external_link) referencing + // other tables. + // ---------------------------------------------------------------------------------- + @ManyToOne(optional = false) + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + + @ManyToOne(optional = false) + @JoinColumn(name = "user_id", referencedColumnName = "id") + private User user; + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; } - public Project getProject() { - return this.project; - } - - public String getUrl() { - return this.url; - } - - public User getUser() { - return this.user; - } - - public String getDescription() { - return this.description; - } - public void setId(Long id) { this.id = id; } - public void setProject(Project project) { - this.project = project; + public String getUrl() { + return this.url; } public void setUrl(String url) { this.url = url; } - public void setUser(User user) { - this.user = user; + public String getDescription() { + return this.description; } public void setDescription(String description) { this.description = description; } - @Override - public String toString() { - return "ExternalLink(id=" + this.getId() + ", project=" + this.getProject() + ", url=" + this.getUrl() + ", user=" + this.getUser() + ", description=" + this.getDescription() + ")"; + public Project getProject() { + return this.project; } + public void setProject(Project project) { + this.project = project; + } + + public User getUser() { + return this.user; + } + + public void setUser(User user) { + this.user = user; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -92,15 +111,28 @@ public class ExternalLink extends DomainObject { && Objects.equals(this.getDescription(), other.getDescription()); } - protected boolean canEqual(final Object other) { - return other instanceof ExternalLink; - } - @Override public int hashCode() { return Objects.hash(this.getId(), this.getProject(), this.getUrl(), this.getUser(), this.getDescription()); } + @Override + public String toString() { + return "ExternalLink(id=" + this.getId() + ", project=" + this.getProject() + + ", url=" + this.getUrl() + ", user=" + this.getUser() + ", description=" + + this.getDescription() + ")"; + } + + // ---------------------------------------------------------------------------------- + // Other method + // ---------------------------------------------------------------------------------- + protected boolean canEqual(final Object other) { + return other instanceof ExternalLink; + } + + // ---------------------------------------------------------------------------------- + // Nested types + // ---------------------------------------------------------------------------------- private static class Builder implements IProject, IURL, IUser, IBuild { private ExternalLink instance = new ExternalLink(); diff --git a/core/src/main/java/se/su/dsv/scipro/workerthreads/WorkerData.java b/core/src/main/java/se/su/dsv/scipro/workerthreads/WorkerData.java index 4827139331..59fefc8d63 100755 --- a/core/src/main/java/se/su/dsv/scipro/workerthreads/WorkerData.java +++ b/core/src/main/java/se/su/dsv/scipro/workerthreads/WorkerData.java @@ -7,7 +7,7 @@ import java.util.Date; import java.util.Objects; @Entity -@Table(name="worker_data") +@Table(name = "worker_data") @Cacheable(true) public class WorkerData extends DomainObject { public WorkerData() { @@ -18,13 +18,13 @@ public class WorkerData extends DomainObject { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(unique=true, nullable=false) + @Column(unique = true, nullable = false) private String name; - @Column(nullable=false) - private Date lastRun=new Date(); + @Column(nullable = false, name = "last_run") + private Date lastRun = new Date(); - @Column(nullable=false) + @Column(nullable = false, name = "last_successful_run") private Date lastSuccessfulRun; @PreUpdate diff --git a/core/src/main/resources/db/migration/V391__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V391__harmonize_table_attribute_name.sql new file mode 100644 index 0000000000..15c116c0ff --- /dev/null +++ b/core/src/main/resources/db/migration/V391__harmonize_table_attribute_name.sql @@ -0,0 +1,3222 @@ +/* + * Step 1: Remove obsolete tables + */ + +drop table plugin_settings; +drop table turnitincheck; + +alter table TurnitinSettings_expirationMails drop foreign key FK_lji32bekgobx76otvw7syu4hb; +drop table TurnitinSettings_expirationMails; + +drop table TurnitinSettings; + +/* + * Step 2: DomainObject related classes and tables. + * + * Many entity classes inherit directly or indirectly from abstract super class DomainObject. Two attributes + * dateCreated and lastModified, have changed mapping to column name with snake case, date_created and last_modified. + * This change affects many, many tables, which are to be managed at first. + */ + +-- table: ActivityPlan + +alter table `ActivityPlan` rename column `dateCreated` to `date_created`; +alter table `ActivityPlan` rename column `lastModified` to `last_modified`; + +-- table: ActivityPlanTemplate + +alter table `ActivityPlanTemplate` rename column `dateCreated` to `date_created`; +alter table `ActivityPlanTemplate` rename column `lastModified` to `last_modified`; + +-- table: ActivityTemplate + +alter table `ActivityTemplate` rename column `dateCreated` to `date_created`; +alter table `ActivityTemplate` rename column `lastModified` to `last_modified`; + +-- table: file_description + +alter table `file_description` rename column `dateCreated` to `date_created`; +alter table `file_description` rename column `lastModified` to `last_modified`; + +-- table: answer + +alter table `answer` rename column `dateCreated` to `date_created`; +alter table `answer` rename column `lastModified` to `last_modified`; + +-- table: ApplicationPeriod + +alter table `ApplicationPeriod` rename column `dateCreated` to `date_created`; +alter table `ApplicationPeriod` rename column `lastModified` to `last_modified`; + +-- table: checklist + +alter table `checklist` rename column `dateCreated` to `date_created`; +alter table `checklist` rename column `lastModified` to `last_modified`; + +-- table: checklist_answer + +alter table `checklist_answer` rename column `dateCreated` to `date_created`; +alter table `checklist_answer` rename column `lastModified` to `last_modified`; + +-- table: checklist_category + +alter table `checklist_category` rename column `dateCreated` to `date_created`; +alter table `checklist_category` rename column `lastModified` to `last_modified`; + +-- table: checklist_question + +alter table `checklist_question` rename column `dateCreated` to `date_created`; +alter table `checklist_question` rename column `lastModified` to `last_modified`; + +-- table: checklist_template + +alter table `checklist_template` rename column `dateCreated` to `date_created`; +alter table `checklist_template` rename column `lastModified` to `last_modified`; + +-- table: comment + +alter table `comment` rename column `dateCreated` to `date_created`; +alter table `comment` rename column `lastModified` to `last_modified`; + +-- table: externallink + +alter table `externallink` rename column `dateCreated` to `date_created`; +alter table `externallink` rename column `lastModified` to `last_modified`; + +-- table: comment_thread + +alter table `comment_thread` rename column `dateCreated` to `date_created`; +alter table `comment_thread` rename column `lastModified` to `last_modified`; + +-- table: FinalSeminarSettings + +alter table `FinalSeminarSettings` rename column `dateCreated` to `date_created`; +alter table `FinalSeminarSettings` rename column `lastModified` to `last_modified`; + +-- table: FinalThesis + +alter table `FinalThesis` rename column `dateCreated` to `date_created`; +alter table `FinalThesis` rename column `lastModified` to `last_modified`; + +-- table: footer_address + +alter table `footer_address` rename column `dateCreated` to `date_created`; +alter table `footer_address` rename column `lastModified` to `last_modified`; + +-- table: footer_link + +alter table `footer_link` rename column `dateCreated` to `date_created`; +alter table `footer_link` rename column `lastModified` to `last_modified`; + +-- table: general_system_settings + +alter table `general_system_settings` rename column `dateCreated` to `date_created`; +alter table `general_system_settings` rename column `lastModified` to `last_modified`; + +-- table: grading_report_template + +alter table `grading_report_template` rename column `dateCreated` to `date_created`; +alter table `grading_report_template` rename column `lastModified` to `last_modified`; + +-- table: project_group + +alter table `project_group` rename column `dateCreated` to `date_created`; +alter table `project_group` rename column `lastModified` to `last_modified`; + +-- table: idea + +alter table `idea` rename column `dateCreated` to `date_created`; +alter table `idea` rename column `lastModified` to `last_modified`; + +-- table: idea_export + +alter table `idea_export` rename column `dateCreated` to `date_created`; +alter table `idea_export` rename column `lastModified` to `last_modified`; + +-- table: mail_event + +alter table `mail_event` rename column `dateCreated` to `date_created`; +alter table `mail_event` rename column `lastModified` to `last_modified`; + +-- table: idea_match + +alter table `idea_match` rename column `dateCreated` to `date_created`; +alter table `idea_match` rename column `lastModified` to `last_modified`; + +-- table: milestone + +alter table `milestone` rename column `dateCreated` to `date_created`; +alter table `milestone` rename column `lastModified` to `last_modified`; + +-- table: NonWorkDayPeriod + +alter table `NonWorkDayPeriod` rename column `dateCreated` to `date_created`; +alter table `NonWorkDayPeriod` rename column `lastModified` to `last_modified`; + +-- table: note + +alter table `note` rename column `dateCreated` to `date_created`; +alter table `note` rename column `lastModified` to `last_modified`; + +-- table: Notification + +alter table `Notification` rename column `dateCreated` to `date_created`; +alter table `Notification` rename column `lastModified` to `last_modified`; + +-- table: NotificationData + +alter table `NotificationData` rename column `dateCreated` to `date_created`; +alter table `NotificationData` rename column `lastModified` to `last_modified`; + +-- table: peer_request + +alter table `peer_request` rename column `dateCreated` to `date_created`; +alter table `peer_request` rename column `lastModified` to `last_modified`; + +-- table: peer_review + +alter table `peer_review` rename column `dateCreated` to `date_created`; +alter table `peer_review` rename column `lastModified` to `last_modified`; + +-- table: preliminary_match + +alter table `preliminary_match` rename column `dateCreated` to `date_created`; +alter table `preliminary_match` rename column `lastModified` to `last_modified`; + +-- table: Program + +alter table `Program` rename column `dateCreated` to `date_created`; +alter table `Program` rename column `lastModified` to `last_modified`; + +-- table: project + +alter table `project` rename column `dateCreated` to `date_created`; +alter table `project` rename column `lastModified` to `last_modified`; + +-- table: project_file + +alter table `project_file` rename column `dateCreated` to `date_created`; +alter table `project_file` rename column `lastModified` to `last_modified`; + +-- table: project_first_meeting + +alter table `project_first_meeting` rename column `dateCreated` to `date_created`; +alter table `project_first_meeting` rename column `lastModified` to `last_modified`; + +-- table: projectPartner + +alter table `projectPartner` rename column `dateCreated` to `date_created`; +alter table `projectPartner` rename column `lastModified` to `last_modified`; + +-- table: project_type_settings + +alter table `project_type_settings` rename column `dateCreated` to `date_created`; +alter table `project_type_settings` rename column `lastModified` to `last_modified`; + +-- table: reviewer_deadline_settings + +alter table `reviewer_deadline_settings` rename column `dateCreated` to `date_created`; +alter table `reviewer_deadline_settings` rename column `lastModified` to `last_modified`; + +-- table: reviewer_target + +alter table `reviewer_target` rename column `dateCreated` to `date_created`; +alter table `reviewer_target` rename column `lastModified` to `last_modified`; + +-- table: unit + +alter table `unit` rename column `dateCreated` to `date_created`; +alter table `unit` rename column `lastModified` to `last_modified`; + +-- table: urkund_submission + +alter table `urkund_submission` rename column `dateCreated` to `date_created`; +alter table `urkund_submission` rename column `lastModified` to `last_modified`; + +-- table: username + +alter table `username` rename column `dateCreated` to `date_created`; +alter table `username` rename column `lastModified` to `last_modified`; + +-- table: user_profile + +alter table `user_profile` rename column `dateCreated` to `date_created`; +alter table `user_profile` rename column `lastModified` to `last_modified`; + +-- table: worker_data + +alter table `worker_data` rename column `dateCreated` to `date_created`; +alter table `worker_data` rename column `lastModified` to `last_modified`; + +-- table: criterion + +alter table `criterion` rename column `dateCreated` to `date_created`; +alter table `criterion` rename column `lastModified` to `last_modified`; + +-- table: grading_criterion_template + +alter table `grading_criterion_template` rename column `dateCreated` to `date_created`; +alter table `grading_criterion_template` rename column `lastModified` to `last_modified`; + +-- table: GradingCriterion + +alter table `GradingCriterion` rename column `dateCreated` to `date_created`; +alter table `GradingCriterion` rename column `lastModified` to `last_modified`; + +-- table: GradingCriterionPoint + +alter table `GradingCriterionPoint` rename column `dateCreated` to `date_created`; +alter table `GradingCriterionPoint` rename column `lastModified` to `last_modified`; + +-- table: grading_criterion_point_template + +alter table `grading_criterion_point_template` rename column `dateCreated` to `date_created`; +alter table `grading_criterion_point_template` rename column `lastModified` to `last_modified`; + +-- table: ReviewerApproval + +alter table `ReviewerApproval` rename column `dateCreated` to `date_created`; +alter table `ReviewerApproval` rename column `lastModified` to `last_modified`; + +-- table: final_seminar_active_participation + +alter table `final_seminar_active_participation` rename column `dateCreated` to `date_created`; +alter table `final_seminar_active_participation` rename column `lastModified` to `last_modified`; + +-- table: final_seminar_opposition + +alter table `final_seminar_opposition` rename column `dateCreated` to `date_created`; +alter table `final_seminar_opposition` rename column `lastModified` to `last_modified`; + +-- table: final_seminar_respondent + +alter table `final_seminar_respondent` rename column `dateCreated` to `date_created`; +alter table `final_seminar_respondent` rename column `lastModified` to `last_modified`; + +-- table: report + +alter table `report` rename column `dateCreated` to `date_created`; +alter table `report` rename column `lastModified` to `last_modified`; + +-- table: notification_delivery_configuration + +alter table `notification_delivery_configuration` rename column `dateCreated` to `date_created`; +alter table `notification_delivery_configuration` rename column `lastModified` to `last_modified`; + +-- table: notification_receiver_configuration + +alter table `notification_receiver_configuration` rename column `dateCreated` to `date_created`; +alter table `notification_receiver_configuration` rename column `lastModified` to `last_modified`; + +-- table: Activity + +alter table `Activity` rename column `dateCreated` to `date_created`; +alter table `Activity` rename column `lastModified` to `last_modified`; + +-- table: final_seminar + +alter table `final_seminar` rename column `dateCreated` to `date_created`; +alter table `final_seminar` rename column `lastModified` to `last_modified`; + +-- table: forum_post + +alter table `forum_post` rename column `dateCreated` to `date_created`; +alter table `forum_post` rename column `lastModified` to `last_modified`; + +-- table: thread + +alter table `thread` rename column `dateCreated` to `date_created`; +alter table `thread` rename column `lastModified` to `last_modified`; + +-- table: Keyword + +alter table `Keyword` rename column `dateCreated` to `date_created`; +alter table `Keyword` rename column `lastModified` to `last_modified`; + +-- table: milestone_activity_template + +alter table `milestone_activity_template` rename column `dateCreated` to `date_created`; +alter table `milestone_activity_template` rename column `lastModified` to `last_modified`; + +-- table: milestone_phase_template + +alter table `milestone_phase_template` rename column `dateCreated` to `date_created`; +alter table `milestone_phase_template` rename column `lastModified` to `last_modified`; + +-- table: Password + +alter table `Password` rename column `dateCreated` to `date_created`; +alter table `Password` rename column `lastModified` to `last_modified`; + +-- table: ProjectType + +alter table `ProjectType` rename column `dateCreated` to `date_created`; +alter table `ProjectType` rename column `lastModified` to `last_modified`; + +-- table: researcharea + +alter table `researcharea` rename column `dateCreated` to `date_created`; +alter table `researcharea` rename column `lastModified` to `last_modified`; + +-- table: user + +alter table `user` rename column `dateCreated` to `date_created`; +alter table `user` rename column `lastModified` to `last_modified`; + +/* + * Step 3: standalone tables + */ + +-- table: worker_data + +alter table `worker_data` rename column `lastRun` to `last_run`; +alter table `worker_data` rename column `lastSuccessfulRun` to `last_successful_run`; + +-- table: footer_link + +alter table `footer_link` rename column `footerColumn` to `footer_column`; + +-- table: NonWorkDayPeriod + +alter table `NonWorkDayPeriod` rename column `endDate` to `end_date`; +alter table `NonWorkDayPeriod` rename column `startDate` to `start_date`; + +rename table `NonWorkDayPeriod` to `non_work_day_period`; + +-- table: reviewer_deadline_settings + +alter table `reviewer_deadline_settings` rename column `roughDraftApproval` to `rough_draft_approval`; +alter table `reviewer_deadline_settings` rename column `finalSeminarApproval` to `final_seminar_approval`; +alter table `reviewer_deadline_settings` rename column `finalGrading` to `final_grading`; + +-- table: final_seminar_settings + +alter table `FinalSeminarSettings` rename column `daysAheadToCreate` to `days_ahead_to_create`; +alter table `FinalSeminarSettings` rename column `daysAheadToRegisterParticipation` to `days_ahead_to_register_participation`; +alter table `FinalSeminarSettings` rename column `daysAheadToRegisterOpposition` to `days_ahead_to_register_opposition`; +alter table `FinalSeminarSettings` rename column `daysAheadToUploadThesis` to `days_ahead_to_upload_thesis`; +alter table `FinalSeminarSettings` rename column `thesisMustBePDF` to `thesis_must_be_pdf`; +alter table `FinalSeminarSettings` rename column `evaluationURL` to `evaluation_url`; +alter table `FinalSeminarSettings` rename column `oppositionPriorityDays` to `opposition_priority_days`; + +rename table `FinalSeminarSettings` to `final_seminar_settings`; + +/* + * Step 4: general_system_settings and three related tables. + */ + +-- table: general_system_settings_system_module + +alter table `general_system_settings_system_modules` drop foreign key `general_system_settings_system_modules_ibfk_1`; +alter table `general_system_settings_system_modules` drop key `GeneralSystemSettings_id`; +alter table `general_system_settings_system_modules` drop primary key; + +alter table `general_system_settings_system_modules` rename column `GeneralSystemSettings_id` to `general_system_settings_id`; +alter table `general_system_settings_system_modules` rename column `systemModules` to `system_module`; + +rename table `general_system_settings_system_modules` to `general_system_settings_system_module`; + +alter table `general_system_settings_system_module` add primary key (general_system_settings_id, system_module); + +alter table `general_system_settings_system_module` + add constraint fk_general_system_settings_system_module_id + foreign key (general_system_settings_id) references general_system_settings (id) + on delete cascade on update cascade; + +-- table: general_system_settings_supervisor_change_recipient + +alter table `general_system_settings_supervisor_change_recipients` drop foreign key `FK7DA712D52AC37675`; +alter table `general_system_settings_supervisor_change_recipients` drop key `FK7DA712D52AC37675`; + +alter table `general_system_settings_supervisor_change_recipients` rename column `GeneralSystemSettings_id` to `general_system_settings_id`; + +rename table `general_system_settings_supervisor_change_recipients` to `general_system_settings_supervisor_change_recipient`; + +alter table `general_system_settings_supervisor_change_recipient` add primary key (general_system_settings_id, mail); + +alter table `general_system_settings_supervisor_change_recipient` + add constraint fk_general_system_settings_supervisor_change_recipient_id + foreign key (general_system_settings_id) references general_system_settings (id) + on delete cascade on update cascade; + +-- table: general_system_settings_alarm_recipient + +alter table `general_system_settings_alarm_recipients` drop foreign key `FK3C9272B2AC37675`; +alter table `general_system_settings_alarm_recipients` drop key `FK3C9272B2AC37675`; + +alter table `general_system_settings_alarm_recipients` rename column `GeneralSystemSettings_id` to `general_system_settings_id`; + +rename table `general_system_settings_alarm_recipients` to `general_system_settings_alarm_recipient`; + +alter table `general_system_settings_alarm_recipient` add primary key (general_system_settings_id, mail); + +alter table `general_system_settings_alarm_recipient` + add constraint fk_general_system_settings_alarm_recipient_id + foreign key (general_system_settings_id) references general_system_settings (id) + on delete cascade on update cascade; + +-- table: general_system_settings + +alter table `general_system_settings` rename column `daisyProfileLinkBaseURL` to `daisy_profile_link_base_url`; +alter table `general_system_settings` rename column `daisySelectResearchAreaURL` to `daisy_select_research_area_url`; +alter table `general_system_settings` rename column `projectPartnerDaysToLive` to `project_partner_days_to_live`; +alter table `general_system_settings` rename column `mailNotifications` to `mail_notifications`; +alter table `general_system_settings` rename column `mailFromName` to `mail_from_name`; +alter table `general_system_settings` rename column `systemFromMail` to `system_from_mail`; +alter table `general_system_settings` rename column `smtpServer` to `smtp_server`; +alter table `general_system_settings` rename column `peerDisplayLatestReviews` to `peer_display_latest_reviews`; +alter table `general_system_settings` rename column `numberOfLatestReviewsDisplayed` to `number_of_latest_reviews_displayed`; +alter table `general_system_settings` rename column `publicReviewsActivated` to `public_reviews_activated`; +alter table `general_system_settings` rename column `peerDownloadEnabled` to `peer_download_enabled`; +alter table `general_system_settings` rename column `sciproURL` to `scipro_url`; +alter table `general_system_settings` rename column `showSingleSignOn` to `show_single_sign_on`; +alter table `general_system_settings` rename column `matchResponsibleMail` to `match_responsible_mail`; +alter table `general_system_settings` rename column `reviewerSupportMail` to `reviewer_support_mail`; +alter table `general_system_settings` rename column `thesisSupportMail` to `thesis_support_mail`; +alter table `general_system_settings` rename column `externalRoomBookingURL` to `external_room_booking_url`; +alter table `general_system_settings` rename column `externalGettingStartedWithIdeaURL` to `external_getting_started_with_idea_url`; +alter table `general_system_settings` rename column `externalGradingURL` to `external_grading_url`; +alter table `general_system_settings` rename column `finalSurveyAvailable` to `final_survey_available`; +alter table `general_system_settings` rename column `activeProjectIdeaSupportMail` to `active_project_idea_support_mail`; + +/* + * Step 5: table user and related tables. + * + * Table user is one of four fundamental tables (other three: project, file_reference, ProjectType). All four + * tables have many foreign keys referenced to them. + * + * Related tables of table user are the tables which have no relationship with other three fundamental tables. Their + * foreign key references end at table user. + */ + +-- table: Program and user_program + +alter table `user_program` drop foreign key `user_program_program_id`; +alter table `user_program` drop key `user_program_program_id`; + +alter table `user_program` drop foreign key `user_program_user_id`; + +rename table `Program` to `program`; + +alter table `program` rename column `externalId` to `external_id`; +alter table `program` rename column `name` to `name_sv`; +alter table `program` rename column `nameEn` to `name_en`; + +alter table `user_program` + add constraint fk_user_program_program_id + foreign key (program_id) references program (id) + on delete cascade on update cascade; + +alter table `user_program` + add constraint fk_user_program_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: note + +alter table `note` drop foreign key `note_ibfk_1`; +alter table `note` drop key `user_id`; + +alter table `note` + add constraint fk_note_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: comment and comment_thread + +alter table `comment` drop foreign key `FK38A5EE5FE44F4DBE`; +alter table `comment` drop foreign key `FK38A5EE5F45F802F5`; +alter table `comment` drop key `FK38A5EE5FE44F4DBE`; +alter table `comment` drop key `FK38A5EE5F45F802F5`; + +alter table `comment_thread` drop key `UK_s0ve8ppa3snl8i1wocqwiuwn2`; +alter table `comment_thread` drop key `commentableKey`; + +alter table comment_thread rename column `commentableId` to `commentable_id`; +alter table comment_thread rename column `commentableKey` to `commentable_key`; + +alter table `comment_thread` add constraint uk_comment_thread_id_key unique(commentable_id, commentable_key); + +alter table comment rename column `commentThread_id` to `comment_thread_id`; +alter table comment rename column `creator_id` to `creator_user_id`; + +alter table `comment` + add constraint fk_comment_creator_user_id + foreign key (creator_user_id) references user (id) + on delete cascade on update cascade; + +alter table `comment` + add constraint fk_comment_comment_thread_id + foreign key (comment_thread_id) references comment_thread (id) + on delete cascade on update cascade; + +-- table: reviewer_target + +alter table `reviewer_target` drop foreign key `FK_ReviewerTarget_ReviewerId`; +alter table `reviewer_target` drop key `UK_ReviewerTarget_ReviewerId_Year`; + +alter table `reviewer_target` rename column `reviewer_id` to `reviewer_user_id`; + +alter table `reviewer_target` add constraint uk_reviewer_target_reviewer_user_id_year unique(reviewer_user_id, year); + +alter table `reviewer_target` + add constraint fk_reviewer_target_reviewer_user_id + foreign key (reviewer_user_id) references user (id) + on delete cascade on update cascade; + +-- table: notification_delivery_configuration + +alter table `notification_delivery_configuration` drop foreign key `FK7B2EE5BF895349BF`; +alter table `notification_delivery_configuration` drop key `FK7B2EE5BF895349BF`; +alter table `notification_delivery_configuration` drop key `one_setting_per_user`; + +alter table `notification_delivery_configuration` add constraint uk_one_setting_per_user unique(type, event, method, user_id); + +alter table `notification_delivery_configuration` + add constraint fk_notification_delivery_configuration_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: username + +alter table `username` drop foreign key `FK_17moq4bksxe30ihucce3jovdc`; +alter table `username` drop key `FK_17moq4bksxe30ihucce3jovdc`; +alter table `username` drop key `username_must_be_unique`; + +alter table `username` add constraint uk_username unique(username); + +alter table `username` + add constraint fk_username_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: user_role + +alter table `user_role` drop foreign key `user_role_user_id`; + +alter table `user_role` + add constraint fk_user_role_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: user_languages + +alter table `user_languages` drop foreign key `user_languages_user_id`; +alter table `user_languages` drop key `user_languages_user_id`; + +rename table `user_languages` to `user_language`; + +alter table `user_language` + add constraint fk_user_language_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +/* + * table: user, unit and Password + */ + +alter table `user` drop foreign key `FK_hpmviec1b7vdg23xtxsalwxw8`; +alter table `user` drop key `FK_hpmviec1b7vdg23xtxsalwxw8`; + +alter table `user` drop foreign key `user_unit_id`; +alter table `user` drop key `user_unit_id`; + +alter table `user` drop key `identifier`; +alter table `user` drop key `deleted_index`; + +-- rename columns in table user + +alter table `user` rename column `emailAddress` to `email_address`; +alter table `user` rename column `firstName` to `first_name`; +alter table `user` rename column `lastName` to `last_name`; +alter table `user` rename column `fullName` to `full_name`; +alter table `user` rename column `degreeType` to `degree_type`; + +alter table `user` add constraint uk_user_identifier unique(identifier); +create index idx_user_deleted on user(deleted); + +-- table: unit + +alter table `unit` drop key `identifier`; + +alter table `unit` rename column `matchResponsible` to `match_responsible`; + +alter table `unit` add constraint uk_unit_identifier unique(identifier); + +-- add FK from user to unit + +alter table `user` + add constraint fk_user_unit_id + foreign key (unit_id) references unit (id) + on delete cascade on update cascade; + +-- table: Password + +alter table `Password` drop foreign key `FK_43erxladp39q03wrco68hi9iq`; +alter table `Password` drop key `FK_43erxladp39q03wrco68hi9iq`; +alter table `Password` drop key `FK4C641EBB895349BF`; +alter table `Password` drop key `deleted_index`; +alter table `Password` drop key `UK_43erxladp39q03wrco68hi9iq`; +alter table `Password` drop key `user_id`; + +rename table `Password` to `password`; + +alter table `password` add constraint uk_password_user_id unique(user_id); +create index idx_password_deleted on password(deleted); + +alter table `password` + add constraint fk_password_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- add FK from user till password + +alter table `user` + add constraint fk_user_password_id + foreign key (password_id) references password (id) + on delete cascade on update cascade; + +-- table: user_profile + +alter table `user_profile` drop foreign key `FK_user_profile_user`; +alter table `user_profile` drop key `FK487E2135895349BF`; +alter table `user_profile` drop key `UK_ebc21hy5j7scdvcjt0jy6xxrv`; +alter table `user_profile` drop key `user_id`; + +alter table `user_profile` rename column `otherInfo` to `other_info`; +alter table `user_profile` rename column `phoneNumber` to `phone_number`; +alter table `user_profile` rename column `skypeId` to `skype_id`; +alter table `user_profile` rename column `mailCompilation` to `mail_compilation`; +alter table `user_profile` drop column `threadedForum`; +alter table `user_profile` rename column `defaultSupervisorFilter` to `default_supervisor_filter`; +alter table `user_profile` rename column `selectedRole` to `selected_role`; + +alter table `user_profile` add constraint uk_user_profile_user_id unique(user_id); + +alter table `user_profile` + add constraint fk_user_profile_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: user_profile_default_project_status_filter + +alter table `UserProfile_defaultProjectStatusFilter` drop foreign key `FK_user_profile_project_status_user_profile`; +alter table `UserProfile_defaultProjectStatusFilter` drop key `FK_icub74l6htav89sx85ar4qcqg`; + +rename table `UserProfile_defaultProjectStatusFilter` to `user_profile_default_project_status_filter`; + +alter table `user_profile_default_project_status_filter` rename column `UserProfile_id` to `user_profile_id`; +alter table `user_profile_default_project_status_filter` rename column `defaultProjectStatusFilter` to `default_project_status_filter`; + +alter table `user_profile_default_project_status_filter` + add constraint fk_user_profile_default_project_status_filter_user_profile_id + foreign key (user_profile_id) references user_profile (id) + on delete cascade on update cascade; + +-- table: user_profile_default_project_team_member_roles_filter + +alter table `UserProfile_defaultProjectTeamMemberRolesFilter` drop foreign key `FK_user_profile_role_user_profile`; +alter table `UserProfile_defaultProjectTeamMemberRolesFilter` drop key `FK_ibub74l6htav89sx85ar4qcqg`; + +rename table `UserProfile_defaultProjectTeamMemberRolesFilter` to `user_profile_default_project_team_member_roles_filter`; + +alter table `user_profile_default_project_team_member_roles_filter` rename column `UserProfile_id` to `user_profile_id`; +alter table `user_profile_default_project_team_member_roles_filter` rename column `defaultProjectTeamMemberRolesFilter` to `default_project_team_member_roles_filter`; + +alter table `user_profile_default_project_team_member_roles_filter` + add constraint fk_up_dp_tm_roles_filter_user_profile_id + foreign key (user_profile_id) references user_profile (id) + on delete cascade on update cascade; + +/* + * Step 6: table ProjectType and related tables. + * + * Table ProjectType is one of four fundamental tables (other three: project, file_reference, user). All four + * tables have many foreign keys referenced to them. + * + * Table ProjectType has 12 foreign keys referenced to it, this part is the most complex part of this refactoring. + */ + +-- table: user_profile_ProjectType, except foreign key to coming table project_type + +alter table `user_profile_ProjectType` drop foreign key `FK_user_profile_project_type_user_profile`; +alter table `user_profile_ProjectType` drop foreign key `FK_76s8320kw3w7bxp6lw7pmawfh`; +alter table `user_profile_ProjectType` drop key `FK_2blea2vk0b5cvgxjo1fy4p2j0`; +alter table `user_profile_ProjectType` drop key `FK_76s8320kw3w7bxp6lw7pmawfh`; + +rename table `user_profile_ProjectType` to `user_profile_project_type`; + +alter table `user_profile_project_type` rename column `defaultProjectTypeFilter_id` to `project_type_id`; + +alter table `user_profile_project_type` + add constraint fk_user_profile_project_type_user_profile_id + foreign key (user_profile_id) references user_profile (id) + on delete cascade on update cascade; + +-- table: ExternalResource, except foreign key to coming table project_type + +alter table `ExternalResource` drop foreign key `ExternalResource_ProjectType_relevantFor`; +alter table `ExternalResource` drop key `ExternalResource_ProjectType_relevantFor`; + +rename table `ExternalResource` to `external_resource`; + +alter table `external_resource` rename column `relevantFor_id` to `project_type_id`; + +-- table: project_type_project_modules, except foreign key to coming table project_type + +alter table `project_type_project_modules` drop foreign key `FK_4attsf1e22qpveesgl6o9b7lg`; +alter table `project_type_project_modules` drop key `FK_4attsf1e22qpveesgl6o9b7lg`; +alter table `project_type_project_modules` drop primary key; + +rename table `project_type_project_modules` to `project_type_project_module`; + +alter table `project_type_project_module` rename column `ProjectType_id` to `project_type_id`; +alter table `project_type_project_module` rename column `projectModules` to `project_module`; + +alter table `project_type_project_module` add primary key (project_type_id, project_module); + +-- table: project_type_settings, except foreign key to coming table project_type + +alter table `project_type_settings` drop foreign key `FK_project_class_settings_projectType`; +alter table `project_type_settings` drop key `FK_oxqyb1t8jo7cq2fx8j9slvloa`; +alter table `project_type_settings` drop key `UK_project_class_settings_projectType`; + +alter table `project_type_settings` rename column `numDaysBetweenPeerReviewsOnSameProject` to `num_days_between_peer_reviews_on_same_project`; +alter table `project_type_settings` rename column `numDaysToSubmitPeerReview` to `num_days_to_submit_peer_review`; +alter table `project_type_settings` rename column `projectType_id` to `project_type_id`; +alter table `project_type_settings` rename column `numDaysBeforePeerGetsCancelled` to `num_days_before_peer_gets_cancelled`; +alter table `project_type_settings` rename column `minAuthors` to `min_authors`; +alter table `project_type_settings` rename column `maxAuthors` to `max_authors`; +alter table `project_type_settings` rename column `maxFinalSeminarActiveParticipation` to `max_final_seminar_active_participation`; +alter table `project_type_settings` rename column `maxOpponentsOnFinalSeminar` to `max_opponents_on_final_seminar`; +alter table `project_type_settings` rename column `minFinalSeminarActiveParticipation` to `min_final_seminar_active_participation`; +alter table `project_type_settings` rename column `minOpponentsOnFinalSeminar` to `min_opponents_on_final_seminar`; +alter table `project_type_settings` rename column `minimumOppositionsToBeGraded` to `min_oppositions_to_be_graded`; +alter table `project_type_settings` rename column `minimumActiveParticipationsToBeGraded` to `min_active_participations_to_be_graded`; + +alter table `project_type_settings` add constraint uk_project_type_settings_project_type_id unique(project_type_id); + +-- table: grading_report_template, except foreign key to coming table project_type + +alter table `grading_report_template` drop foreign key `FK_grading_report_template_projectType`; +alter table `grading_report_template` drop key `FK_qovbb9ql33oaxprfr01w7ss9u`; +alter table `grading_report_template` drop key `UK_only_one_template_per_date_and_type`; + +alter table `grading_report_template` change `projectType_id` `project_type_id` bigint(20) not null after `failing_grade`; + +alter table `grading_report_template` add constraint uk_grading_report_template_project_type_id_valid_from unique(project_type_id, valid_from); + +-- table: grading_report_template_grade_limits + +alter table `grading_report_template_grade_limits` drop foreign key `FK_grade_limit_grading_report_template `; +alter table `grading_report_template_grade_limits` drop key `UK_one_grade_per_template`; + +rename table `grading_report_template_grade_limits` to `grading_report_template_grade_limit`; + +alter table `grading_report_template_grade_limit` change `grading_report_template_id` `grading_report_template_id` bigint(20) default null after `lower_limit`; + +alter table `grading_report_template_grade_limit` add constraint uk_grt_gl_grading_report_template_id_grade unique (grading_report_template_id, grade); + +alter table `grading_report_template_grade_limit` + add constraint fk_grt_gl_grading_report_template_id + foreign key (grading_report_template_id) references grading_report_template (id) + on delete cascade on update cascade; + +/* >>> START: table grading_criterion_template, GradingCriterion and criterion share same JPA MappedSuperclass, must be handled together. */ + +-- table: criterion (partially, only rename three columns, since this table criterion shares same +-- JPA MappedSuperclass AbstractCriterion with grading_criterion_template, and GradingCriterion + +alter table `criterion` rename column `title` to `title_sv`; +alter table `criterion` rename column `titleEn` to `title_en`; +alter table `criterion` rename column `sortOrder` to `sort_order`; + +-- table: GradingCriterion (partially, only rename four columns, since this table GradingCriterion shares same +-- JPA MappedSuperclass AbstractCriterion and AbstractGradingCriterion with grading_criterion_template. + +alter table `GradingCriterion` rename column `title` to `title_sv`; +alter table `GradingCriterion` rename column `titleEn` to `title_en`; +alter table `GradingCriterion` rename column `sortOrder` to `sort_order`; +alter table `GradingCriterion` rename column `pointsRequiredToPass` to `points_required_to_pass`; + +-- table: grading_criterion_template + +alter table `grading_criterion_template` drop foreign key `FK_b37xw6uyfj98ff2tsn5t8x5q`; +alter table `grading_criterion_template` drop key `FK_b37xw6uyfj98ff2tsn5t8x5q`; + +alter table `grading_criterion_template` rename column `title` to `title_sv`; +alter table `grading_criterion_template` rename column `titleEn` to `title_en`; +alter table `grading_criterion_template` rename column `sortOrder` to `sort_order`; +alter table `grading_criterion_template` rename column `pointsRequiredToPass` to `points_required_to_pass`; +alter table `grading_criterion_template` rename column `gradingReportTemplate_id` to `grading_report_template_id`; + +alter table `grading_criterion_template` + add constraint fk_gct_grading_report_template_id + foreign key (grading_report_template_id) references grading_report_template (id) + on delete cascade on update cascade; + +/* >>> END: */ + +/* >>> START: table grading_criterion_point_template and GradingCriterionPoint share same JPA MappedSuperclass, must be handled together. */ + +-- table: GradingCriterionPoint (partially, only rename two columns since this table and grading_criterion_pint_template +-- shares same MappedSuperclass AbstractGradingCriterionPoint. + +alter table `GradingCriterionPoint` rename column `description` to `description_sv`; +alter table `GradingCriterionPoint` rename column `descriptionEn` to `description_en`; + +-- table: grading_criterion_point_template + +alter table `grading_criterion_point_template` drop foreign key `FK_gradingCriterionTemplate_id`; +alter table `grading_criterion_point_template` drop key `FK_gradingCriterionTemplate_id`; + +alter table `grading_criterion_point_template` rename column `description` to `description_sv`; +alter table `grading_criterion_point_template` rename column `descriptionEn` to `description_en`; +alter table `grading_criterion_point_template` rename column `gradingCriterionTemplate_id` to `grading_criterion_template_id`; + +alter table `grading_criterion_point_template` + add constraint fk_gc_pt_grading_criterion_template_id + foreign key (grading_criterion_template_id) references grading_criterion_template (id) + on delete cascade on update cascade; + +/* >>> END: */ + +-- table: checklist_template_ProjectType, except foreign key to coming table project_type + +alter table `checklist_template_ProjectType` drop foreign key `FK_checklist_template_projectType_id`; +alter table `checklist_template_ProjectType` drop foreign key `FK_checklist_template_degree_level_checklist_template_id`; +alter table `checklist_template_ProjectType` drop key `FK_checklist_template_projectType_id`; +alter table `checklist_template_ProjectType` drop primary key; + +rename table `checklist_template_ProjectType` to `checklist_template_project_type`; + +alter table `checklist_template_project_type` rename column `projectType_id` to `project_type_id`; + +alter table `checklist_template_project_type` add primary key (checklist_template_id, project_type_id); + +alter table `checklist_template_project_type` + add constraint fk_ct_pt_checklist_template_id + foreign key (checklist_template_id) references checklist_template (id) + on delete cascade on update cascade; + +-- table: milestone_activity_template_ProjectType, except foreign key to coming table project_type + +alter table `milestone_activity_template_ProjectType` drop foreign key `FKFB3FC75180E42A0F`; +alter table `milestone_activity_template_ProjectType` drop foreign key `FKFB3FC75157F6B071`; +alter table `milestone_activity_template_ProjectType` drop key `FKFB3FC75180E42A0F`; +alter table `milestone_activity_template_ProjectType` drop key `FKFB3FC75157F6B071`; +alter table `milestone_activity_template_ProjectType` drop primary key; + +rename table `milestone_activity_template_ProjectType` to `milestone_activity_template_project_type`; + +alter table `milestone_activity_template_project_type` rename column `projectTypes_id` to `project_type_id`; + +alter table `milestone_activity_template_project_type` add primary key (`milestone_activity_template_id`, `project_type_id`); + +alter table `milestone_activity_template_project_type` + add constraint fk_ma_tpt_milestone_activity_template_id + foreign key (milestone_activity_template_id) references milestone_activity_template (id) + on delete cascade on update cascade; + +-- table: idea, we only remove foreign key from idea to ProjectType and rename the column projectType_id here. +-- This table has many related tables and will be fixed later. + +alter table `idea` drop foreign key `FK_idea_projectType`; +alter table `idea` drop key `FK_idea_projectType`; + +alter table `idea` rename column `projectType_id` to `project_type_id`; + +-- table: project, we only remove foreign key from project to ProjectType and rename the column projectType_id here. +-- This table has many related tables and will be fixed later. + +alter table `project` drop foreign key `FK_project_projectType`; +alter table `project` drop key `FKED904B19B2B6081F`; + +alter table `project` rename column `projectType_id` to `project_type_id`; + +/* + * Table target, projectPartner and ApplicationPeriodProjectType has not only foreign key referencing table ProjectType, + * but also foreign key referencing table ApplicationPeriod. Table ApplicationPeriodProjectType references to + * ActivityPlanTemplate as well. + * + * Table ActivityTemplate, ActivityPlanTemplate, ApplicationPeriod using camel case naming convention, + * ApplicationPeriod has a related table, applicationperiodexemption, and they all need to + * fixed as well, before ProjectType can be fixed. A foreign key from table idea to ApplicationPeriod needs to be removed + * before table ApplicationPeriod can be fixed. + * + * Removal of foreign keys and renaming of columns and table name must be fixed in following order: + * + * 1. target, projectPartner, ApplicationPeriodProjectType + * 2. ActivityTemplate and ActivityPlanTemplate + * 3. ApplicationPeriod, applicationperiodexcemption, and idea as well + * + * Foreign keys will be then added in reverse order, it's like a stack pop. + */ + +-- >>> STACK PUSH: 1st table group: target, projectPartner, ApplicationPeriodProjectType + +-- table: target, except foreign key to coming table project_type, and application_period + +alter table `target` drop foreign key `target_user_id`; +alter table `target` drop foreign key `FKCB7E7191A520201Eb`; +alter table `target` drop foreign key `FKCB7E7191790761A4b`; +alter table `target` drop key `FKCB7E7191A520201E`; +alter table `target` drop key `FKCB7E7191790761A4`; +alter table `target` drop primary key; + +alter table `target` rename column `applicationPeriodId` to `application_period_id`; +alter table `target` rename column `projectTypeId` to `project_type_id`; + +alter table `target` add primary key (application_period_id, project_type_id, user_id); + +alter table `target` + add constraint fk_target_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: projectPartner, except foreign key to coming table project_type, and application_period + +alter table `projectPartner` drop foreign key `FK_project_partner_project_type`; +alter table `projectPartner` drop foreign key `FK_ProjectPartner_ApplicationPeriod_applicationPeriod`; +alter table `projectPartner` drop foreign key `FK1882B6F895349BF`; +alter table `projectPartner` drop key `FK_ProjectPartner_ApplicationPeriod_applicationPeriod`; +alter table `projectPartner` drop key `FK_project_partner_project_type`; +alter table `projectPartner` drop key `FK1882B6F895349BF`; + +rename table `projectPartner` to `project_partner`; + +alter table `project_partner` rename column `infotext` to `info_text`; +alter table `project_partner` rename column `projectType_id` to `project_type_id`; +alter table `project_partner` rename column `applicationPeriod_id` to `application_period_id`; + +alter table `project_partner` + add constraint fk_project_partner_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: ApplicationPeriodProjectType, except foreign key to coming table application_period, project_type and activity_plan_template. + +alter table `ApplicationPeriodProjectType` drop foreign key `FK_hqebt63rl2mhogp66dy5m7upo`; +alter table `ApplicationPeriodProjectType` drop foreign key `FK_546usee339qh4g5otguwka3hi`; +alter table `ApplicationPeriodProjectType` drop foreign key `FK_3ku67jvegs1xxh8ykk023i7sb`; +alter table `ApplicationPeriodProjectType` drop key `FK_3ku67jvegs1xxh8ykk023i7sb`; +alter table `ApplicationPeriodProjectType` drop key `FK_546usee339qh4g5otguwka3hi`; +alter table `ApplicationPeriodProjectType` drop key `FK_hqebt63rl2mhogp66dy5m7upo`; +alter table `ApplicationPeriodProjectType` drop primary key; + +rename table `ApplicationPeriodProjectType` to `application_period_project_type`; + +alter table `application_period_project_type` rename column `applicationPeriod_id` to `application_period_id`; +alter table `application_period_project_type` rename column `projectType_id` to `project_type_id`; +alter table `application_period_project_type` rename column `activityPlanTemplate_id` to `activity_plan_template_id`; + +alter table `application_period_project_type` add primary key (application_period_id, project_type_id); + +-- >>> STACK PUSH: 2nd table group: ActivityPlanTemplate and ActivityTemplate + +-- table: ActivityTemplate, except foreign key to coming table activity_plan_template + +alter table `ActivityTemplate` drop foreign key `FK_ca5bhq3i6p2g292fo5l4fqtf`; +alter table `ActivityTemplate` drop foreign key `FK_activity_template_checklist_template`; +alter table `ActivityTemplate` drop key `FKD4434665C5FC509F`; +alter table `ActivityTemplate` drop key `FK_ca5bhq3i6p2g292fo5l4fqtf`; +alter table `ActivityTemplate` drop key `FK_667ye6la0yb5obk64v21knimn`; + +rename table `ActivityTemplate` to `activity_template`; + +alter table `activity_template` rename column `numberInOrder` to `number_in_order`; +alter table `activity_template` rename column `activityPlanTemplate_id` to `activity_plan_template_id`; +alter table `activity_template` rename column `daysOffset` to `days_offset`; +alter table `activity_template` rename column `checkListTemplate_id` to `checklist_template_id`; + +alter table `activity_template` + add constraint fk_activity_template_checklist_template_id + foreign key (checklist_template_id) references checklist_template (id) + on delete set null on update cascade; + +-- table: ActivityPlanTemplate (at this stage, no any foreign key is referenced to ActivityPlanTemplate) + +alter table `ActivityPlanTemplate` drop foreign key `FK_rgwf80yvcy2msbb6g80bae10p`; +alter table `ActivityPlanTemplate` drop key `FK_rgwf80yvcy2msbb6g80bae10p`; +alter table `ActivityPlanTemplate` drop key `FKACCF6522E44F4DBE`; + +rename table `ActivityPlanTemplate` to `activity_plan_template`; + +alter table `activity_plan_template` rename column `isSysAdminTemplate` to `is_sys_admin_template`; +alter table `activity_plan_template` rename column `creator_id` to `creator_user_id`; + +alter table `activity_plan_template` + add constraint fk_activity_plan_template_creator_user_id + foreign key (creator_user_id) references user (id) + on delete cascade on update cascade; + +-- Add back all foreign key references to activity_plan_template + +-- add foreign key reference from activity_template to activity_plan_template +alter table `activity_template` + add constraint fk_activity_template_activity_plan_template_id + foreign key (activity_plan_template_id) references activity_plan_template (id) + on delete cascade on update cascade; + +-- add foreign key reference from application_period_project_type to activity_plan_template +alter table `application_period_project_type` + add constraint fk_ap_pt_activity_plan_template_id + foreign key (activity_plan_template_id) references activity_plan_template (id) + on delete cascade on update cascade; + +-- >>> STACK POP: 2nd table group (ActivityPlanTemplate and ActivityTemplate) is done!!! + +-- >>> STACK PUSH: 3rd table group: ApplicationPeriod, applicationperiodexemption, idea + +-- table: applicationperiodexeption, except foreign key reference to coming table application_period + +alter table `applicationperiodexemption` drop foreign key `fk_application_period_exemption_user`; +alter table `applicationperiodexemption` drop foreign key `fk_application_period_exemption_application_period`; +alter table `applicationperiodexemption` drop foreign key `FK_4p3he5fymtmdgbkl3xwrodq36`; +alter table `applicationperiodexemption` drop key `i_user_application_period`; +alter table `applicationperiodexemption` drop key `i_application_period`; +alter table `applicationperiodexemption` drop key `i_user`; +alter table `applicationperiodexemption` drop key `FK_4p3he5fymtmdgbkl3xwrodq36`; +alter table `applicationperiodexemption` drop primary key; + +rename table `applicationperiodexemption` to `application_period_exemption`; + +alter table `application_period_exemption` rename column `endDate` to `end_date`; +alter table `application_period_exemption` rename column `grantedBy_id` to `granted_by_id`; +alter table `application_period_exemption` rename column `grantedOn` to `granted_on`; +alter table `application_period_exemption` rename column `applicationPeriodId` to `application_period_id`; + +alter table `application_period_exemption` add primary key (`application_period_id`,`user_id`,`type`); + +alter table `application_period_exemption` + add constraint fk_ape_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +alter table `application_period_exemption` + add constraint fk_ape_granted_by_id + foreign key (granted_by_id) references user (id) + on delete cascade on update cascade; + +-- table: idea, we only remove foreign key from idea to ApplicationPeriod and rename the column applicationPeriod_id here. +-- This table has many related tables and will be fixed later. + +alter table `idea` drop foreign key `FK6E051897BEC322C1`; +alter table `idea` drop key `FK6E051897BEC322C1`; + +alter table `idea` rename column `applicationPeriod_id` to `application_period_id`; + +-- table: ApplicationPeriod (at this stage, no any foreign key is referenced to ApplicationPeriod) + +rename table `ApplicationPeriod` to `application_period`; + +alter table `application_period` rename column `endDate` to `end_date`; +alter table `application_period` rename column `startDate` to `start_date`; +alter table `application_period` rename column `courseStartDate` to `course_start_date`; +alter table `application_period` rename column `courseEndDate` to `course_end_date`; + +-- Add back all foreign key references to application_period, since table application_period is ready + +-- add back foreign key reference from ide to application_period +alter table `idea` + add constraint fk_idea_application_period_id + foreign key (application_period_id) references application_period (id) + on delete cascade on update cascade; + +-- add back foreign key reference from application_period_exemption to application_period +alter table `application_period_exemption` + add constraint fk_ape_application_period_id + foreign key (application_period_id) references application_period (id) + on delete cascade on update cascade; + +-- >>> STACK POP: 3rd table group: ApplicationPeriod, applicationperiodexemption, idea is done!!! + +-- add back foreign key reference from application_period_project_type to application_period +alter table `application_period_project_type` + add constraint fk_ap_pt_application_period_id + foreign key (application_period_id) references application_period (id) + on delete cascade on update cascade; + +-- add back foreign key reference from project_partner to application_period +alter table `project_partner` + add constraint fk_project_partner_application_period_id + foreign key (application_period_id) references application_period (id) + on delete cascade on update cascade; + +-- add back foreign key reference from target to application_period +alter table `target` + add constraint fk_target_application_period_id + foreign key (application_period_id) references application_period (id) + on delete cascade on update cascade; + +-- table: ProjectType (finally!! at this stage, no any foreign key is referenced to ProjectType) + +rename table `ProjectType` to `project_type`; + +alter table `project_type` rename column `degreeType` to `degree_type`; + +-- Add back all foreign key references to project_type + +-- add back foreign key reference from application_period_project_type to project_type +alter table `application_period_project_type` + add constraint fk_ap_pt_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from project_partner to project_type +alter table `project_partner` + add constraint fk_project_partner_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from target to project_type +alter table `target` + add constraint fk_target_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- >>> STACK POP: 1st table group: target, projectPartner, ApplicationPeriodProjectType is done!!! + +-- add back foreign key reference from project to project_type +alter table `project` + add constraint fk_project_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from idea to project_type +alter table `idea` + add constraint fk_idea_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from milestone_activity_template_project_type to project_type +alter table `milestone_activity_template_project_type` + add constraint fk_ma_tpt_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from checklist_template_project_type to project_type +alter table `checklist_template_project_type` + add constraint fk_ct_pt_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from grading_report_template to project_type +alter table `grading_report_template` + add constraint fk_grading_report_template_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from project_type_settings to project_type +alter table `project_type_settings` + add constraint fk_project_type_settings_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from project_type_project_module to project_type +alter table `project_type_project_module` + add constraint fk_project_type_project_module_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from external_resource to project_type +alter table `external_resource` + add constraint fk_external_resource_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +-- add back foreign key reference from user_profile_project_type to project_type. +alter table `user_profile_project_type` + add constraint fk_user_profile_project_type_project_type_id + foreign key (project_type_id) references project_type (id) + on delete cascade on update cascade; + +/* + * Step 7: checklist related tables + */ + +-- table: checklist_checklist_question + +alter table `checklist_checklist_question` drop foreign key `FKC77ED98C64F9D54`; +alter table `checklist_checklist_question` drop foreign key `FKC77ED981F327355`; +alter table `checklist_checklist_question` drop key `FKC77ED981F327355`; +alter table `checklist_checklist_question` drop key `FKC77ED98C64F9D54`; +alter table `checklist_checklist_question` drop key `UK_o5ndj9lydqv17attv7uf8wlr`; +alter table `checklist_checklist_question` drop key `questions_id`; +alter table `checklist_checklist_question` drop primary key; + +alter table `checklist_checklist_question` rename column `questions_id` to `checklist_question_id`; + +alter table `checklist_checklist_question` add primary key (checklist_id, checklist_question_id); + +alter table `checklist_checklist_question` add constraint uk_ccq_checklist_question_id unique(checklist_question_id); + +alter table `checklist_checklist_question` + add constraint fk_ccq_checklist_question_id + foreign key (checklist_question_id) references checklist_question (id) + on delete cascade on update cascade; + +alter table `checklist_checklist_question` + add constraint fk_ccq_checklist_id + foreign key (checklist_id) references checklist (id) + on delete cascade on update cascade; + +-- table: Checklist_userLastOpenDate + +alter table `Checklist_userLastOpenDate` drop foreign key `FKF7E07AB26D025A9`; +alter table `Checklist_userLastOpenDate` drop foreign key `FKF7E07AB21F327355`; +alter table `Checklist_userLastOpenDate` drop key `FKF7E07AB26D025A9`; +alter table `Checklist_userLastOpenDate` drop key `FKF7E07AB21F327355`; +alter table `Checklist_userLastOpenDate` drop primary key; + +rename table `Checklist_userLastOpenDate` to `checklist_user_last_open_date`; + +alter table `checklist_user_last_open_date` rename column `CheckList_id` to `checklist_id`; +alter table `checklist_user_last_open_date` rename column `userLastOpenDate` to `last_open_date`; +alter table `checklist_user_last_open_date` rename column `userLastOpenDate_KEY` to `user_id`; + +alter table `checklist_user_last_open_date` add primary key (checklist_id, user_id); + +alter table `checklist_user_last_open_date` + add constraint fk_cu_lod_checklist_id + foreign key (checklist_id) references checklist(id) + on delete cascade on update cascade; + +alter table `checklist_user_last_open_date` + add constraint fk_cu_lod_user_id + foreign key (user_id) references user(id) + on delete cascade on update cascade; + +-- table: checklist_checklist_category + +alter table `checklist_checklist_category` drop foreign key `FK54F86EB08725F1D`; +alter table `checklist_checklist_category` drop foreign key `FK54F86EB01F327355`; +alter table `checklist_checklist_category` drop key `FK54F86EB08725F1D`; +alter table `checklist_checklist_category` drop key `FK54F86EB01F327355`; + +alter table `checklist_checklist_category` rename column `categories_id` to `checklist_category_id`; + +alter table `checklist_checklist_category` + add constraint fk_cca_checklist_id + foreign key (checklist_id) references checklist (id) + on delete cascade on update cascade; + +alter table `checklist_checklist_category` + add constraint fk_cca_checklist_category_id + foreign key (checklist_category_id) references checklist_category (id) + on delete cascade on update cascade; + +-- table: checklist_category + +alter table `checklist_category` drop key `categoryName`; +alter table `checklist_category` rename column `categoryName` to `category_name`; + +alter table `checklist_category` add constraint uk_checklist_category_category_name unique(category_name); + +-- table: checklist + +alter table `checklist` drop foreign key `FK_checklist_project`; +alter table `checklist` drop key `I_checkList_activity`; + +alter table `checklist` + add constraint fk_checklist_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- table : checklist_question_checklist_answer + +alter table `checklist_question_checklist_answer` drop foreign key `FK86395A5787D18D44`; +alter table `checklist_question_checklist_answer` drop foreign key `FK86395A574BFBD702`; +alter table `checklist_question_checklist_answer` drop key `FK86395A574BFBD702`; +alter table `checklist_question_checklist_answer` drop key `UK_47is0po5b69467hxbgr4a2gph`; +alter table `checklist_question_checklist_answer` drop key `answers_id`; + +alter table `checklist_question_checklist_answer` rename column `answers_id` to `checklist_answer_id`; + +alter table `checklist_question_checklist_answer` add constraint uk_cq_ca_checklist_answer_id unique(checklist_answer_id); + +alter table `checklist_question_checklist_answer` + add constraint fk_cq_ca_checklist_answer_id + foreign key (checklist_answer_id) references checklist_answer (id) + on delete cascade on update cascade; + +alter table `checklist_question_checklist_answer` + add constraint fk_cq_ca_checklist_question_id + foreign key (checklist_question_id) references checklist_question (id) + on delete cascade on update cascade; + +-- table: checklist_answer + +alter table `checklist_answer` drop foreign key `FK49936477895349BF`; +alter table `checklist_answer` drop key `FK49936477895349BF`; + +alter table `checklist_answer` + add constraint fk_checklist_answer_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- update to NOT_APPLICABLE because of typo in code +update `checklist_answer` set answer = 'NOT_APPLICABLE' where answer = 'NOT_APLICABLE'; +update `answer` set answer = 'NOT_APPLICABLE' where answer = 'NOT_APLICABLE'; + +-- table: checklist_question + +alter table `checklist_question` rename column `questionNumber` to `question_number`; + +-- table: ChecklistTemplate_questions + +alter table `ChecklistTemplate_questions` drop foreign key `FK872F7C0E869F0235`; +alter table `ChecklistTemplate_questions` drop key `FK872F7C0E869F0235`; + +rename table `ChecklistTemplate_questions` to `checklist_template_question`; + +alter table `checklist_template_question` rename column `CheckListTemplate_id` to `checklist_template_id`; +alter table `checklist_template_question` rename column `questions` to `question`; + +alter table `checklist_template_question` + add constraint fk_ctq_checklist_template_id + foreign key (checklist_template_id) references checklist_template (id) + on delete cascade on update cascade; + +-- table: checklist_template_checklist_category + +alter table `checklist_template_checklist_category` drop foreign key `FK4E82F4438725F1D`; +alter table `checklist_template_checklist_category` drop foreign key `FK4E82F44372B51E82`; +alter table `checklist_template_checklist_category` drop key `FK4E82F4438725F1D`; +alter table `checklist_template_checklist_category` drop key `FK4E82F44372B51E82`; + +alter table `checklist_template_checklist_category` rename column `categories_id` to `checklist_category_id`; + +alter table `checklist_template_checklist_category` + add constraint fk_ct_cc_checklist_template_id + foreign key (checklist_template_id) references checklist_template (id) + on delete cascade on update cascade; + +alter table `checklist_template_checklist_category` + add constraint fk_ct_cc_checklist_category_id + foreign key (checklist_category_id) references checklist_category (id) + on delete cascade on update cascade; + +-- table: checklist_template + +alter table `checklist_template` drop foreign key `FK14DA6F3E44F4DBE`; +alter table `checklist_template` drop key `FK14DA6F3E44F4DBE`; + +alter table `checklist_template` rename column `creator_id` to `creator_user_id`; +alter table `checklist_template` rename column `templateNumber` to `template_number`; + +alter table `checklist_template` + add constraint fk_checklist_template_creator_user_id + foreign key (creator_user_id) references user (id) + on delete cascade on update cascade; + +/* + * Step 8: Survey related related tables + */ + +-- table: SurveyAnswer_multipleAnswers, except foreign key to coming table survey_answer + +alter table `SurveyAnswer_multipleAnswers` drop foreign key `FK_SA`; +alter table `SurveyAnswer_multipleAnswers` drop key `FK_SA`; + +rename table `SurveyAnswer_multipleAnswers` to `survey_answer_multiple_answers`; + +alter table `survey_answer_multiple_answers` rename column `SurveyAnswer_id` to `survey_answer_id`; +alter table `survey_answer_multiple_answers` rename column `multipleAnswers` to `multiple_answers`; + +-- table: SurveyAnswer, except foreign key to coming table survey and question + +alter table `SurveyAnswer` drop foreign key `FK_answer_question`; +alter table `SurveyAnswer` drop foreign key `FK_answer_survey`; +alter table `SurveyAnswer` drop key `FK_answer_question`; +alter table `SurveyAnswer` drop key `FK_answer_survey`; + +rename table `SurveyAnswer` to `survey_answer`; + +-- add back foreign key reference from survey_answer_multiple_answers to survey_answer + +alter table `survey_answer_multiple_answers` + add constraint fk_sama_survey_answer_id + foreign key (survey_answer_id) references survey_answer (id) + on delete cascade on update cascade; + +-- table: Question_choices, except foreign key to coming table question + +alter table `Question_choices` drop foreign key `FK_question_choices_question`; +alter table `Question_choices` drop key `FK_question_choices_question`; + +rename table `Question_choices` to `question_choices`; + +-- table: Question + +rename table `Question` to `question`; + +-- add back foreign key reference from question_choices to question + +alter table `question_choices` + add constraint fk_question_choices_question_id + foreign key (question_id) references question (id) + on delete cascade on update cascade; + +-- add back foreign key references from survey_answer to question + +alter table `survey_answer` + add constraint fk_survey_answer_question_id + foreign key (question_id) references question (id) + on delete cascade on update cascade; + +-- table: survey + +alter table `Survey` drop foreign key `FK_survey_project`; +alter table `Survey` drop key `FK_survey_project`; +alter table `Survey` drop foreign key `FK_survey_user`; +alter table `Survey` drop key `FK_survey_user`; + +rename table `Survey` to `survey`; + +alter table `survey` + add constraint fk_survey_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `survey` + add constraint fk_survey_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- add back foreign key references from survey_answer to survey + +alter table `survey_answer` + add constraint fk_survey_answer_survey_id + foreign key (survey_id) references survey (id) + on delete cascade on update cascade; + +/* + * Step 9: Keyword and Research Area related tables + */ + +-- table: Keyword_researcharea, except foreign keys to coming table keyword and research_area + +alter table `Keyword_researcharea` drop foreign key `FKF8C66F5E98ED461`; +alter table `Keyword_researcharea` drop key `FKF8C66F5E98ED461`; +alter table `Keyword_researcharea` drop foreign key `FKF8C66F5E6F20ECBC`; +alter table `Keyword_researcharea` drop key `FKF8C66F5E6F20ECBC`; + +rename table `Keyword_researcharea` to `keyword_research_area`; + +alter table `keyword_research_area` rename column `Keyword_id` to `keyword_id`; +alter table `keyword_research_area` rename column `researchAreas_id` to `research_area_id`; + +-- table: idea_Keyword + +alter table `idea_Keyword` drop foreign key `FK3707EE21AE316F00`; +alter table `idea_Keyword` drop key `FK3707EE21AE316F00`; +alter table `idea_Keyword` drop foreign key `FK3707EE21BD1521C1`; + +alter table `idea_Keyword` drop primary key; + +rename table `idea_Keyword` to `idea_keyword`; + +alter table `idea_keyword` rename column `keywords_id` to `keyword_id`; + +alter table `idea_keyword` add primary key (idea_id, keyword_id); + +alter table `idea_keyword` + add constraint fk_idea_keyword_idea_id + foreign key (idea_id) references idea (id) + on delete cascade on update cascade; + +-- table: keyword + +alter table `Keyword` drop key `deleted_index`; + +rename table `Keyword` to `keyword`; + +create index idx_keyword_deleted on keyword (deleted); + +-- add back foreign key reference from table idea_keyword to table keyword + +alter table `idea_keyword` + add constraint fk_idea_keyword_keyword_id + foreign key (keyword_id) references keyword (id) + on delete cascade on update cascade; + +-- add back foreign key reference from table keyword_research_area to table keyword + +alter table `keyword_research_area` + add constraint fk_kra_keyword_id + foreign key (keyword_id) references keyword (id) + on delete cascade on update cascade; + +-- table: user_research_area + +alter table `user_research_area` drop foreign key `user_research_area_user_id`; +alter table `user_research_area` drop foreign key `user_research_area_research_area_id`; +alter table `user_research_area` drop key `user_research_area_research_area_id`; + +alter table `user_research_area` + add constraint fk_ura_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- drop foreign key from idea to table researcharea before we can proceed with that table, +-- change foreign key column name as well + +alter table `idea` drop foreign key `FK6E0518974E257FBF`; +alter table `idea` drop key `FK6E0518974E257FBF`; + +alter table `idea` rename column `researchArea_id` to `research_area_id`; + +-- drop foreign key from project to table researcharea before we can proceed with that table, +-- change foreign key column name as well + +alter table `project` drop foreign key `FK_research_area_id`; +alter table `project` drop key `FK_research_area_id`; + +alter table `project` rename column `researchArea_id` to `research_area_id`; + +-- table: researcharea + +alter table `researcharea` drop key `deleted_index`; +alter table `researcharea` drop key `identifier`; + +rename table `researcharea` to `research_area`; + +create index idx_research_area_deleted on research_area (deleted); + +alter table `research_area` add constraint uk_research_area_identifier unique (identifier); + +-- add back foreign key reference from table project to table research_area + +alter table `project` + add constraint fk_project_research_area_id + foreign key (research_area_id) references research_area (id) + on delete cascade on update cascade; + +-- add back foreign key reference from table idea to table research_area + +alter table `idea` + add constraint fk_idea_research_area_id + foreign key (research_area_id) references research_area (id) + on delete cascade on update cascade; + +-- add back foreign key reference from table user_research_area to table research_area + +alter table `user_research_area` + add constraint fk_ura_research_area_id + foreign key (research_area_id) references research_area (id) + on delete cascade on update cascade; + +-- add back foreign key reference from table keyword_research_area to table research_area + +alter table `keyword_research_area` + add constraint fk_kra_research_area_id + foreign key (research_area_id) references research_area (id) + on delete cascade on update cascade; + +/* + * Step 10: idea related tables + */ + +-- table: idea + +alter table `idea` drop foreign key `FK6E051897B9431B73`; +alter table `idea` drop foreign key `FK6E051897C1813915`; +alter table `idea` drop foreign key `FK6E051897E44F4DBE`; + +alter table `idea` drop key `FK6E051897C1813915`; +alter table `idea` drop key `FK6E051897B9431B73`; +alter table `idea` drop key `FK6E051897E44F4DBE`; + +alter table `idea` drop key `UK_only_one_idea_per_project`; + +alter table `idea` change `published` `published` bit(1) not null default b'1' after `type`; +alter table `idea` change `cachedStatus` `cached_status` varchar(255) default null after `published`; +alter table `idea` change `inactive` `inactive` tinyint(1) not null default 0 after `cached_status`; + +alter table `idea` change `practicalHow` `practical_how` longtext default null after `inactive`; +alter table `idea` change `theoryHow` `theory_how` longtext default null after `practical_how`; +alter table `idea` change `literature` `literature` longtext default null after `why`; + +alter table `idea` change `background` `background` longtext default null after `literature`; +alter table `idea` change `problem` `problem` longtext default null after `background`; +alter table `idea` change `method` `method` longtext default null after `problem`; +alter table `idea` change `interests` `interests` longtext default null after `method`; + +alter table `idea` rename column `creator_id` to `creator_user_id`; +alter table `idea` rename column `match_id` to `latest_match_id`; + +alter table `idea` add constraint uk_idea_project_id unique(project_id); + +alter table `idea` + add constraint fk_idea_creator_user_id + foreign key (creator_user_id) references user (id) + on delete cascade on update cascade; + +alter table `idea` + add constraint fk_idea_latest_match_id + foreign key (latest_match_id) references idea_match (id) + on delete cascade on update cascade; + +alter table `idea` + add constraint fk_idea_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- table: idea_language + +alter table `idea_language` drop foreign key `FK_idea_language_idea`; +alter table `idea_language` drop key `FK_idea_language_idea`; + +alter table `idea_language` + add constraint fk_idea_language_idea_id + foreign key (idea_id) references idea (id) + on delete cascade on update cascade; + +-- table: idea_export + +alter table `idea_export` drop foreign key `FK68FA705CFCDADF61`; +alter table `idea_export` drop key `FK68FA705CFCDADF61`; + +alter table `idea_export` + add constraint fk_idea_export_idea_id + foreign key (idea_id) references idea (id) + on delete cascade on update cascade; + +-- table: idea_first_meeting + +alter table `idea_first_meeting` drop foreign key `FK9393AA04FCDADF61`; +alter table `idea_first_meeting` drop key `FK9393AA04FCDADF61`; + +alter table `idea_first_meeting` drop key `UK_k4m4tupnikallbq3cq3llvlmk`; +alter table `idea_first_meeting` drop key `idea_id`; + +alter table `idea_first_meeting` rename column `firstMeetingDate` to `first_meeting_date`; +alter table `idea_first_meeting` change `room` `room` longtext not null after `first_meeting_date`; + +alter table `idea_first_meeting` + add constraint fk_idea_first_meeting_idea_id + foreign key (idea_id) references idea (id) + on delete cascade on update cascade; + +alter table `idea_first_meeting` + add constraint uk_idea_first_meeting_idea_id unique(idea_id); + +-- table: idea_match + +alter table `idea_match` drop foreign key `FK87EA481DFCDADF61`; +alter table `idea_match` drop foreign key `FK87EA481DA89FFB7F`; +alter table `idea_match` drop foreign key `idea_match_supervisor_id`; + +alter table `idea_match` drop key `FK87EA481DFCDADF61`; +alter table `idea_match` drop key `FK87EA481DA89FFB7F`; +alter table `idea_match` drop key `idea_match_supervisor_id`; + +alter table `idea_match` rename column `changedBy_id` to `changed_by_user_id`; +alter table `idea_match` rename column `supervisor_id` to `supervisor_user_id`; + +alter table `idea_match` + add constraint fk_idea_match_idea_id + foreign key (idea_id) references idea (id) + on delete cascade on update cascade; + +alter table `idea_match` + add constraint fk_idea_match_changed_by_user_id + foreign key (changed_by_user_id) references user (id) + on delete cascade on update cascade; + +alter table `idea_match` + add constraint fk_idea_match_supervisor_user_id + foreign key (supervisor_user_id) references user (id) + on delete cascade on update cascade; + +-- table: preliminary_match + +alter table `preliminary_match` drop foreign key `FK_preliminary_match_supervisor`; +alter table `preliminary_match` drop foreign key `FK_preliminary_match_idea`; + +alter table `preliminary_match` drop key `FK_preliminary_match_supervisor`; +alter table `preliminary_match` drop key `FK_preliminary_match_idea`; + +alter table `preliminary_match` change `comment` `comment` mediumtext default null after `version`; +alter table `preliminary_match` rename column `supervisor_id` to `supervisor_user_id`; + +alter table `preliminary_match` + add constraint fk_preliminary_match_idea_id + foreign key (idea_id) references idea (id) + on delete cascade on update cascade; + +alter table `preliminary_match` + add constraint fk_preliminary_match_supervisor_user_id + foreign key (supervisor_user_id) references user (id) + on delete cascade on update cascade; + +-- table: idea_student + +alter table `idea_student` drop foreign key `idea_student_user_id`; +alter table `idea_student` drop foreign key `FK9458BA93FCDADF61`; + +alter table `idea_student` drop key `idea_student_user_id`; +alter table `idea_student` drop key `FK9458BA93FCDADF61`; +alter table `idea_student` drop key `FK_c5py593l4g261jdkuvwdmcmgj`; + +alter table `idea_student` rename column `dateCreated` to `date_created`; +alter table `idea_student` change `id` `id` bigint(20) not null auto_increment first; + +alter table `idea_student` + add constraint fk_idea_student_idea_id + foreign key (idea_id) references idea (id) + on delete cascade on update cascade; + +alter table `idea_student` + add constraint fk_idea_student_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +/* + * Step 11: activity related tables + * + * Some tables of this group of tables need to be renamed. Because of how foreign keys reference to each other + * between them, the order and behavior of how the tables will be fixed looks like stack again. + * + * 1. Remove references from activity_final_seminar, activity_thread, project_first_meeting to activity, + * the fix these three tables, but wait to later before foreign keys are added back to becoming activity table. + * 2. Remove reference from Activity to ActivtyPlan, and fix table Activity, without adding back foreign key to + * becoming activity_plan table. + * 3. Fix ActivityPlan table, rename it to activity_plan. + * 4. Add back foreign key reference from activity to activity_plan + * 5. Add back foreign key reference from activity_final_seminar, activity_thread, project_first_meeting to + * activity table. + */ + +-- table: activity_final_seminar, except foreign key to becoming table activity + +alter table `activity_final_seminar` drop foreign key `activity_final_seminar_ibfk_2`; +alter table `activity_final_seminar` drop foreign key `activity_final_seminar_ibfk_1`; + +alter table `activity_final_seminar` drop key `activity_id`; + +alter table `activity_final_seminar` + add constraint fk_afs_final_seminar_id + foreign key (final_seminar_id) references final_seminar (id) + on delete cascade on update cascade; + +-- table: activity_thread, except foreign key to becoming table activity + +alter table `activity_thread` drop foreign key `FK_activity_thread_project_thread`; +alter table `activity_thread` drop foreign key `FK_activity_thread_activity`; + +alter table `activity_thread` drop key `FK_activity_thread_project_thread`; + +alter table `activity_thread` + add constraint fk_activity_thread_project_thread_id + foreign key (project_thread_id) references project_thread (id) + on delete cascade on update cascade; + +-- table: project_first_meeting, except foreign key to becoming table activity + +alter table `project_first_meeting` drop foreign key `FK_project_first_meeting_activity`; + +alter table `project_first_meeting` drop key `FK_project_first_meeting_activity`; + +alter table `project_first_meeting` change `room` `room` longtext not null after `version`; + +alter table `project_first_meeting` change `activity_id` `activity_id` bigint(20) not null after `room`; + +-- table: activity + +alter table `Activity` drop foreign key `FK_Activity_file_upload`; +alter table `Activity` drop foreign key `FK_Activity_ActivityPlan`; +alter table `Activity` drop foreign key `FK_activity_checkList`; + +alter table `Activity` drop key `FK_Activity_file_upload`; +alter table `Activity` drop key `activityTemplate_id_index`; +alter table `Activity` drop key `deleted_index`; +alter table `Activity` drop key `UK_activity_checkList`; + +rename table `Activity` to `activity`; + +alter table `activity` change `title` `title` varchar(500) not null after `deleted`; +alter table `activity` change `action` `action` varchar(64) not null default 'none' after `description`; +alter table `activity` change `editable` `editable` bit(1) not null default b'1' after `action`; + +alter table `activity` rename column `activityTemplate_id` to `activity_plan_id`; +alter table `activity` rename column `file_upload_reference_id` to `upload_file_reference_id`; + +alter table `activity` add constraint uk_activity_checklist_id unique (checklist_id); +create index idx_activity_deleted on activity(deleted); + +alter table `activity` + add constraint `fk_activity_checklist_id` + foreign key (checklist_id) references checklist (id) + on delete cascade on update cascade ; + +alter table `activity` + add constraint `fk_activity_upload_file_reference_id` + foreign key (upload_file_reference_id) references file_reference (id) + on delete cascade on update cascade ; + +-- table: ActivityPlan + +alter table `ActivityPlan` drop foreign key `fk_ActivityPlan_project_B`; +alter table `ActivityPlan` drop key `project_id`; + +rename table `ActivityPlan` to `activity_plan`; + +alter table `activity_plan` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `activity_plan` change `startDate` `start_date` datetime default null after `version`; + +alter table `activity_plan` add constraint uk_activity_plan_project_id unique (project_id); + +alter table `activity_plan` + add constraint `fk_activity_plan_project_id` + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- add foreign key reference from activity to activity_plan + +alter table `activity` + add constraint fk_activity_activity_plan_id + foreign key (activity_plan_id) references activity_plan (id) + on delete cascade on update cascade; + +-- Add back all foreign key references to activity + +-- add foreign key reference from project_first_meeting to activity + +alter table `project_first_meeting` + add constraint fk_project_first_meeting_activity_id + foreign key (activity_id) references activity (id) + on delete cascade on update cascade; + +-- add foreign key reference from activity_thread to activity + +alter table `activity_thread` + add constraint fk_activity_thread_activity_id + foreign key (activity_id) references activity (id) + on delete cascade on update cascade; + +-- add foreign key reference from activity_final_seminar to activity + +alter table `activity_final_seminar` + add constraint fk_afs_activity_id + foreign key (activity_id) references activity (id) + on delete cascade on update cascade; + +/* + * Step 12: Peer Review related tables + */ + +-- table: peer_request + +alter table `peer_request` drop foreign key `FK_peer_request_checklist_template`; +alter table `peer_request` drop foreign key `FK_peer_request_file`; +alter table `peer_request` drop foreign key `FK_ppnisfed4ipbg17rts8vbuqt8`; +alter table `peer_request` drop foreign key `peer_request_reviewer_id`; + +alter table `peer_request` drop key `FK_peer_request_file`; +alter table `peer_request` drop key `FK_ppnisfed4ipbg17rts8vbuqt8`; +alter table `peer_request` drop key `peer_request_reviewer_id`; +alter table `peer_request` drop key `FK514488B2869F0235`; +alter table `peer_request` drop key `FK514488B2C1813915`; + +alter table `peer_request` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `peer_request` change `language` `language` varchar(255) not null after `status`; + +alter table `peer_request` rename column `checkListTemplate_id` to `checklist_template_id`; +alter table `peer_request` rename column `requester_id` to `requester_user_id`; + +alter table `peer_request` change `checklist_template_id` `checklist_template_id` bigint(20) default null after `language`; +alter table `peer_request` change `file_reference_id` `file_reference_id` bigint(20) not null after `checklist_template_id`; + +alter table `peer_request` + add constraint fk_peer_request_checklist_template_id + foreign key (checklist_template_id) references checklist_template (id) + on delete set null on update cascade; + +alter table `peer_request` + add constraint fk_peer_request_file_reference_id + foreign key (file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `peer_request` + add constraint fk_peer_request_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `peer_request` + add constraint fk_peer_request_requester_user_id + foreign key (requester_user_id) references user (id) + on delete cascade on update cascade; + +-- table: peer_review + +alter table `peer_review` drop foreign key `peer_review_reviewer_id`; +alter table `peer_review` drop foreign key `FK_n5wj0qsev5cf8acm0xhfrqlpg`; +alter table `peer_review` drop foreign key `FK_9ke7armwg3tfnghmschgo011f`; +alter table `peer_review` drop foreign key `FK_peer_review_file`; + +alter table `peer_review` drop key `peer_review_reviewer_id`; +alter table `peer_review` drop key `FK_n5wj0qsev5cf8acm0xhfrqlpg`; +alter table `peer_review` drop key `FKB00C90D5C1813915`; +alter table `peer_review` drop key `FK_9ke7armwg3tfnghmschgo011f`; +alter table `peer_review` drop key `FKB00C90D5CEE8709B`; +alter table `peer_review` drop key `FK_peer_review_file`; + +alter table `peer_review` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `peer_review` change `status` `status` varchar(255) not null after `comment`; +alter table `peer_review` change `deadline` `deadline` datetime not null after `status`; + +alter table `peer_review` change `file_reference_id` `file_reference_id` bigint(20) default null after `deadline`; +alter table `peer_review` change `peerRequest_id` `peer_request_id` bigint(20) not null; +alter table `peer_review` change `reviewer_id` `reviewer_user_id` bigint(20) not null; + +alter table `peer_review` + add constraint fk_peer_review_file_reference_id + foreign key (file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `peer_review` + add constraint fk_peer_review_peer_request_id + foreign key (peer_request_id) references peer_request (id) + on delete cascade on update cascade; + +alter table `peer_review` + add constraint fk_peer_review_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `peer_review` + add constraint fk_peer_review_reviewer_user_id + foreign key (reviewer_user_id) references user (id) + on delete cascade on update cascade; + +-- table: answer + +alter table `answer` drop foreign key `FK_64r70sbiishrkuj1vn87vo53k`; + +alter table `answer` drop key `FK_64r70sbiishrkuj1vn87vo53k`; +alter table `answer` drop key `FKABCA3FBE2C41A959`; + +alter table `answer` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `answer` change `question` `question` longtext not null after `version`; +alter table `answer` change `answer` `answer` varchar(255) not null after `question`; + +alter table `answer` rename column `peerReview_id` to `peer_review_id`; + +alter table `answer` + add constraint fk_answer_peer_review_id + foreign key (peer_review_id) references peer_review (id) + on delete cascade on update cascade; + +/* + * Step 13: Milestone related tables + */ + +-- table: milestone + +alter table `milestone` drop foreign key `FKC0841970667E5A5E`; +alter table `milestone` drop foreign key `FKC0841970C1813915`; +alter table `milestone` drop foreign key `milestone_user_id`; + +alter table `milestone` drop key `FKC0841970667E5A5E`; +alter table `milestone` drop key `FKC0841970C1813915`; +alter table `milestone` drop key `milestone_user_id`; + +alter table `milestone` rename column `activity_id` to `milestone_activity_template_id`; + +alter table `milestone` + add constraint fk_milestone_milestone_activity_template_id + foreign key (milestone_activity_template_id) references milestone_activity_template (id) + on delete cascade on update cascade; + +alter table `milestone` + add constraint fk_milestone_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `milestone` + add constraint fk_milestone_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: milestone_activity_template, except foreign key to becoming table event + +alter table `milestone_activity_template` drop foreign key `milestone_activity_template_ibfk_1`; +alter table `milestone_activity_template` drop foreign key `FK42DAA8FE233E1A72`; + +alter table `milestone_activity_template` drop key `milestone_activity_template_ibfk_1`; +alter table `milestone_activity_template` drop key `FK42DAA8FE233E1A72`; +alter table `milestone_activity_template` drop key `deleted_index`; +alter table `milestone_activity_template` drop key `code`; + +alter table `milestone_activity_template` change `description` `description` varchar(255) default null after `title`; +alter table `milestone_activity_template` change `sortOrder` `sort_order` int(11) default null; +alter table `milestone_activity_template` change `editableByStudents` `editable_by_students` bit(1) not null default b'0' after `sort_order`; + +alter table `milestone_activity_template` change `phase` `milestone_phase_template_id` bigint(20) not null; +alter table `milestone_activity_template` change `activatedBy` `activated_by_event_name` varchar(191) default null; + +alter table `milestone_activity_template` add constraint uk_milestone_activity_template_code unique(code); + +create index idx_milestone_activity_template_deleted on milestone_activity_template (deleted); + +alter table `milestone_activity_template` + add constraint fk_mat_milestone_phase_template_id + foreign key (milestone_phase_template_id) references milestone_phase_template (id) + on delete cascade on update cascade; + +-- table: event + +rename table `Event` to `event`; + +-- add foreign key reference from milestone_activity_template to event +alter table `milestone_activity_template` + add constraint fk_mat_activated_by_event_name + foreign key (activated_by_event_name) references event (name) + on delete cascade on update cascade; + +-- table: milestone_phase_template + +alter table `milestone_phase_template` drop key `deleted_index`; + +alter table `milestone_phase_template` change `description` `description` varchar(255) default null after `title`; + +alter table `milestone_phase_template` rename column `sortOrder` to `sort_order`; + +create index idx_milestone_phase_template_deleted on milestone_phase_template (deleted); + +/* + * Step 14: Final Seminar related tables + */ + +-- table: final_seminar + +alter table `final_seminar` drop foreign key `FK_rv1p7wl0dnj25saiarmk55yvr`; +alter table `final_seminar` drop foreign key `FK_final_seminar_document_reference`; + +alter table `final_seminar` drop key `FK_final_seminar_document_reference`; +alter table `final_seminar` drop key `FK_rv1p7wl0dnj25saiarmk55yvr`; +alter table `final_seminar` drop key `deleted_index`; +alter table `final_seminar` drop key `FK49900D28C1813915`; + +alter table `final_seminar` drop key `UK_rv1p7wl0dnj25saiarmk55yvr`; + +alter table `final_seminar` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `final_seminar` change `deleted` `deleted` tinyint(1) not null after `version`; + +alter table `final_seminar` change `startDate` `start_date` datetime not null after `deleted`; +alter table `final_seminar` change `room` `room` varchar(255) not null after start_date; +alter table `final_seminar` change `maxOpponents` `max_opponents` int(11) not null after `room`; +alter table `final_seminar` change `maxParticipants` `max_participants` int(11) not null after `max_opponents`; +alter table `final_seminar` change `presentationLanguage` `presentation_lang` varchar(255) not null after `max_participants`; +alter table `final_seminar` change `documentUploadDate` `document_upload_date` datetime default null after `presentation_lang`; +alter table `final_seminar` change `extra_info` `extra_info` text default null after `document_upload_date`; +alter table `final_seminar` change `creationReason` `creation_reason` mediumtext default null after `extra_info`; +alter table `final_seminar` change `manualParticipants` `manual_participants` tinyint(1) not null default 0 after `creation_reason`; +alter table `final_seminar` change `project_id` `project_id` bigint(20) not null after `document_reference_id`; + +alter table `final_seminar` rename column `document_reference_id` to `document_file_reference_id`; + +alter table `final_seminar` add constraint uk_final_seminar_project_id unique(project_id); + +create index idx_final_seminar_deleted on final_seminar (deleted); + +alter table `final_seminar` + add constraint fk_final_seminar_document_file_reference_id + foreign key (document_file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `final_seminar` + add constraint fk_final_seminar_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- table: final_seminar_active_participation + +alter table `final_seminar_active_participation` drop foreign key `final_seminar_active_participation_user_id`; +alter table `final_seminar_active_participation` drop foreign key `FK_mk920fce29yhjgv33wr69fe8a`; +alter table `final_seminar_active_participation` drop foreign key `FK_3si3rx7tv6ke9oeiq0hts3lm0`; + +alter table `final_seminar_active_participation` drop key `FK35AB727FF583C69F`; +alter table `final_seminar_active_participation` drop key `FK35AB727FC1813915`; +alter table `final_seminar_active_participation` drop key `FK_mk920fce29yhjgv33wr69fe8a`; +alter table `final_seminar_active_participation` drop key `FK_3si3rx7tv6ke9oeiq0hts3lm0`; +alter table `final_seminar_active_participation` drop key `final_seminar_active_participation_user_id`; + +alter table `final_seminar_active_participation` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `final_seminar_active_participation` change `grade` `grade` varchar(20) default null after `version`; + +alter table `final_seminar_active_participation` rename column `finalSeminar_id` to `final_seminar_id`; + +alter table `final_seminar_active_participation` + add constraint fk_fsap_final_seminar_id + foreign key (final_seminar_id) references final_seminar (id) + on delete cascade on update cascade; + +alter table `final_seminar_active_participation` + add constraint fk_fsap_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +alter table `final_seminar_active_participation` + add constraint fk_fsap_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- table: final_seminar_opposition + +alter table `final_seminar_opposition` drop foreign key `FK_62i59u7j6x5ma0iydx9no6m4i`; +alter table `final_seminar_opposition` drop foreign key `FK_final_seminar_opposition_report`; +alter table `final_seminar_opposition` drop foreign key `FK_hilhyo3tgq89pm27i4pxjaua`; +alter table `final_seminar_opposition` drop foreign key `final_seminar_opposition_user_id`; + +alter table `final_seminar_opposition` drop key `FK8CD13581F583C69F`; +alter table `final_seminar_opposition` drop key `FK8CD13581C1813915`; +alter table `final_seminar_opposition` drop key `FK_62i59u7j6x5ma0iydx9no6m4i`; +alter table `final_seminar_opposition` drop key `FK_hilhyo3tgq89pm27i4pxjaua`; +alter table `final_seminar_opposition` drop key `final_seminar_opposition_user_id`; +alter table `final_seminar_opposition` drop key `FK_final_seminar_opposition_report`; + +alter table `final_seminar_opposition` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `final_seminar_opposition` change `finalSeminar_id` `final_seminar_id` bigint(20) not null after `feedback`; +alter table `final_seminar_opposition` change `opponent_report_reference_id` + `opponent_report_file_reference_id` bigint(20) default null after `final_seminar_id`; +alter table `final_seminar_opposition` change `project_id` `project_id` bigint(20) not null + after `opponent_report_file_reference_id`; + +alter table `final_seminar_opposition` + add constraint fk_fso_final_seminar_id + foreign key (final_seminar_id) references final_seminar (id) + on delete cascade on update cascade; + +alter table `final_seminar_opposition` + add constraint fk_fso_opponent_report_file_reference_id + foreign key (opponent_report_file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `final_seminar_opposition` + add constraint fk_fso_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `final_seminar_opposition` + add constraint fk_fso_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: final_seminar_respondent + +alter table `final_seminar_respondent` drop foreign key `final_seminar_respondent_user_id`; +alter table `final_seminar_respondent` drop foreign key `FK_final_seminar_respondent_id`; + +alter table `final_seminar_respondent` drop key `FK_final_seminar_respondent_id`; +alter table `final_seminar_respondent` drop key `final_seminar_respondent_user_id`; + +alter table `final_seminar_respondent` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `final_seminar_respondent` change `grade` `grade` varchar(20) default null after `version`; +alter table `final_seminar_respondent` change `finalSeminar_id` `final_seminar_id` bigint(20) not null after `grade`; + +alter table `final_seminar_respondent` + add constraint fk_fsr_final_seminar_id + foreign key (final_seminar_id) references final_seminar (id) + on delete cascade on update cascade; + +alter table `final_seminar_respondent` + add constraint fk_fsr_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +/* + * Step 14: Report and Criterion related tables + */ + +-- table: report + +alter table `report` change `submitted` `submitted` tinyint(1) not null default 0 after `version`; + +-- table: opposition_report + +alter table `opposition_report` drop foreign key `opposition_report_ibfk_1`; +alter table `opposition_report` drop foreign key `FK_opposition_report_seminar_opposition`; +alter table `opposition_report` drop foreign key `FK_opposition_report_attachment`; + +alter table `opposition_report` drop key `FK_opposition_report_attachment`; +alter table `opposition_report` drop key `FK_opposition_report_seminar_opposition`; + +alter table `opposition_report` drop key `UK_one_report_per_opponent`; + +alter table `opposition_report` change `thesisSummary` `thesis_summary` longtext default null after `id`; + +alter table `opposition_report` change `attachment_reference_id` `attachment_file_reference_id` + bigint(20) default null after `thesis_summary`; + +alter table `opposition_report` change `finalSeminarOpposition_id` `final_seminar_opposition_id` + bigint(20) not null after `attachment_file_reference_id`; + +alter table `opposition_report` add constraint uk_or_final_seminar_opposition_id + unique(final_seminar_opposition_id); + +alter table `opposition_report` + add constraint fk_or_id + foreign key (id) references report (id) + on delete cascade on update cascade; + +alter table `opposition_report` + add constraint fk_or_attachment_file_reference_id + foreign key (attachment_file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `opposition_report` + add constraint fk_or_final_seminar_opposition_id + foreign key (final_seminar_opposition_id) references final_seminar_opposition (id) + on delete cascade on update cascade; + +-- table: criterion + +alter table `criterion` drop foreign key `FK_criterion_report`; + +alter table `criterion` drop key `FK_criterion_report`; + +alter table `criterion` change `title_sv` `title_sv` varchar(255) not null after `version`; +alter table `criterion` change `title_en` `title_en` varchar(255) not null default '' after `title_sv`; +alter table `criterion` change `description` `description_sv` varchar(2000) default null after `title_en`; +alter table `criterion` change `descriptionEn` `description_en` varchar(2000) default null after `description_sv`; +alter table `criterion` change `feedback` `feedback` longtext default null after `description_en`; +alter table `criterion` change `report_id` `report_id` bigint(20) not null after `sort_order`; + +alter table `criterion` + add constraint fk_criterion_report_id + foreign key (report_id) references report (id) + on delete cascade on update cascade; + +-- table: GradingCriterionPoint, except foreign key to becoming table grading_criterion + +alter table `GradingCriterionPoint` drop foreign key `FK_GradingCriterion_id`; + +alter table `GradingCriterionPoint` drop key `FK_GradingCriterion_id`; + +alter table `GradingCriterionPoint` change `GradingCriterion_id` `grading_criterion_id` bigint(20) not null + after `description_en`; + +rename table `GradingCriterionPoint` to `grading_criterion_point`; + +-- table: GradingCriterion, except foreign key to becoming table grading_report + +alter table `GradingCriterion` drop foreign key `FK_k2ynx2lcpdl969alj5nt3f7xx`; + +alter table `GradingCriterion` drop key `FK_k2ynx2lcpdl969alj5nt3f7xx`; + +alter table `GradingCriterion` change `title_sv` `title_sv` varchar(255) not null after `version`; +alter table `GradingCriterion` change `title_en` `title_en` varchar(255) not null default '' after `title_sv`; +alter table `GradingCriterion` change `type` `type` varchar(64) not null after `title_en`; +alter table `GradingCriterion` change `points_required_to_pass` `points_required_to_pass` int(11) not null after `type`; +alter table `GradingCriterion` change `feedback` `feedback` longtext default null after `points`; +alter table `GradingCriterion` change `gradingReport_id` `grading_report_id` bigint(20) not null after `flag`; + +rename table `GradingCriterion` to `grading_criterion`; + +-- add foreign key reference from grading_criterion_point to grading_criterion + +alter table `grading_criterion_point` + add constraint fk_gcp_grading_criterion_id + foreign key (grading_criterion_id) references grading_criterion (id) + on delete cascade on update cascade; + +-- table: SupervisorGradingReport, except foreign key to becoming table grading_report + +alter table `SupervisorGradingReport` drop foreign key `supervisor_grading_report_user_id`; +alter table `SupervisorGradingReport` drop foreign key `FK_cwxdypciob8dmndx5elwi3fe5`; + +alter table `SupervisorGradingReport` drop key `supervisor_grading_report_user_id`; +alter table `SupervisorGradingReport` drop key `FK_cwxdypciob8dmndx5elwi3fe5`; + +rename table `SupervisorGradingReport` to `supervisor_grading_report`; + +alter table `supervisor_grading_report` + add constraint fk_sgr_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: ReviewerGradingReport, except foreign key to becoming table grading_report + +alter table `ReviewerGradingReport` drop foreign key `FK_axsaeqbamfc41dhih1s62g998`; + +alter table `ReviewerGradingReport` drop key `FK_axsaeqbamfc41dhih1s62g998`; + +rename table `ReviewerGradingReport` to `reviewer_grading_report`; + +-- table: GradingReport + +alter table `GradingReport` drop foreign key `GradingReport_ibfk_1`; +alter table `GradingReport` drop foreign key `FK_6ygpk1qq218jgwuuyx0bp6vui`; + +alter table `GradingReport` drop key `FK_6ygpk1qq218jgwuuyx0bp6vui`; + +rename table `GradingReport` to `grading_report`; + +alter table `grading_report` + add constraint fk_grading_report_id + foreign key (id) references report (id) + on delete cascade on update cascade; + +alter table `grading_report` + add constraint fk_grading_report_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- add foreign key reference from reviewer_grading_report to grading_report + +alter table `reviewer_grading_report` + add constraint fk_reviewer_grading_report_id + foreign key (id) references grading_report (id) + on delete cascade on update cascade; + +-- add foreign key reference from supervisor_grading_report to grading_report + +alter table `supervisor_grading_report` + add constraint fk_sgr_id + foreign key (id) references grading_report (id) + on delete cascade on update cascade; + +-- add foreign key reference from grading_criterion to grading_report + +alter table `grading_criterion` + add constraint fk_grading_criterion_grading_report_id + foreign key (grading_report_id) references grading_report (id) + on delete cascade on update cascade; + +/* + * Step 15: project and related tables + */ + +-- table: project + +alter table `project` drop foreign key `project_supervisor_id`; +alter table `project` drop key `project_supervisor_id`; +alter table `project` drop key `identifier`; + +alter table `project` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `project` change `title` `title` longtext not null after `version`; +alter table `project` change `credits` `credits` int(11) not null default 0 after `title`; +alter table `project` change `language` `language` varchar(255) default null after credits; +alter table `project` change `start_date` `start_date` date not null after language; +alter table `project` change `expected_end_date` `expected_end_date` date default null after `start_date`; +alter table `project` change `externalOrganization` `external_organization` varchar(255) default null after `expected_end_date`; +alter table `project` change `projectStatus` `project_status` varchar(255) default null after `external_organization`; +alter table `project` change `fs_rule_exmpt` `final_seminar_rule_exmpt` bit(1) not null default b'0' after `project_status`; +alter table `project` change `stateOfMind` `state_of_mind` varchar(255) default null after `final_seminar_rule_exmpt`; +alter table `project` change `stateOfMindReason` `state_of_mind_reason` varchar(255) default null after `state_of_mind`; +alter table `project` change `stateOfMindDate` `state_of_mind_date` datetime default null after `state_of_mind_reason`; +alter table `project` change `identifier` `daisy_identifier` bigint(20) default null after `state_of_mind_date`; +alter table `project` change `supervisor_id` `supervisor_id` bigint(20) not null after `research_area_id`; + +alter table `project` add constraint uk_project_daisy_identifier unique(daisy_identifier); + +alter table `project` + add constraint fk_project_supervisor_id + foreign key (supervisor_id) references user (id) + on delete cascade on update cascade; + +-- table: grading_history_rejections + +alter table `grading_history_rejections` drop foreign key `FK_grading_history_rejections_project`; + +alter table `grading_history_rejections` drop key `FK_grading_history_rejections_project`; + +alter table `grading_history_rejections` change `reason` `reason` text not null after `id`; +alter table `grading_history_rejections` change `when` `when` timestamp not null default '0000-00-00 00:00:00' after `reason`; + +rename table `grading_history_rejections` to `grading_history_rejection`; + +alter table `grading_history_rejection` + add constraint fk_grading_history_rejections_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- table: grading_history_approvals + +alter table `grading_history_approvals` drop foreign key `FK_grading_history_approvals_project`; + +alter table `grading_history_approvals` drop key `FK_grading_history_approvals_project`; + +alter table `grading_history_approvals` change `when` `when` timestamp not null default '0000-00-00 00:00:00' after `id`; + +rename table `grading_history_approvals` to `grading_history_approval`; + +alter table `grading_history_approval` + add constraint fk_grading_history_approval_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- table: national_subject_category + +alter table `national_subject_category` drop key `U_national_subject_category_external_id`; + +alter table `national_subject_category` change `swedish_name` `name_sv` varchar(255) not null after `id`; +alter table `national_subject_category` change `english_name` `name_en` varchar(255) not null after `name_sv`; +alter table `national_subject_category` change `external_id` `external_id` int(11) not null after `preselected`; + +alter table `national_subject_category` + add constraint uk_national_subject_category_external_id unique(external_id); + +-- table: publication_metadata + +alter table `publication_metadata` drop foreign key `FK_publication_metadata_project`; +alter table `publication_metadata` drop foreign key `FK_publication_metadata_national_subject_category`; + +alter table `publication_metadata` drop key `FK_publication_metadata_project`; +alter table `publication_metadata` drop key `FK_publication_metadata_national_subject_category`; + +alter table `publication_metadata` change `project_id` `project_id` bigint(20) not null after `national_subject_category_id`; + +alter table `publication_metadata` change `abstract_swedish` `abstract_sv` text default null after `id`; +alter table `publication_metadata` change `abstract_english` `abstract_en` text default null after `abstract_sv`; +alter table `publication_metadata` change `keywords_swedish` `keywords_sv` text default null after `abstract_en`; +alter table `publication_metadata` change `keywords_english` `keywords_en` text default null after `keywords_sv`; + +alter table `publication_metadata` + add constraint fk_publication_metadata_national_subject_category_id + foreign key (national_subject_category_id) references national_subject_category (id) + on delete cascade on update cascade; + +alter table `publication_metadata` + add constraint fk_publication_metadata_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +/* + * Step 16: Many-to-Many tables between project and user. + */ + +-- table: project_user_note (new changes from develop branch) + +alter table `project_user_note` drop foreign key `FK_project_user_note_user`; +alter table `project_user_note` drop foreign key `FK_project_user_note_project`; +alter table `project_user_note` drop key `FK_project_user_note_user`; + +alter table `project_user_note` + add constraint fk_project_user_note_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `project_user_note` + add constraint fk_project_user_note_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: project_cosupervisor + +alter table `project_cosupervisor` drop foreign key `FK_fj57t069dymdrnnhdxcnfvvnn`; +alter table `project_cosupervisor` drop foreign key `FK_18x2poxkt8s2bw9kpr7vbmd5j`; + +alter table `project_cosupervisor` drop key `FK_fj57t069dymdrnnhdxcnfvvnn`; +alter table `project_cosupervisor` drop key `FK_18x2poxkt8s2bw9kpr7vbmd5j`; + +alter table `project_cosupervisor` change `user_id` `user_id` bigint(20) not null after `project_id`; + +alter table `project_cosupervisor` + add constraint fk_project_cosupervisor_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `project_cosupervisor` + add constraint fk_project_cosupervisor_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: project_reviewer + +alter table `project_reviewer` drop foreign key `FK_g7yryw3e0dtmuuvgw5qjhphjm`; +alter table `project_reviewer` drop foreign key `FK_6aik0jd18kv3383fbt09xd0pi`; + +alter table `project_reviewer` drop key `FK_6aik0jd18kv3383fbt09xd0pi`; +alter table `project_reviewer` drop key `FK_g7yryw3e0dtmuuvgw5qjhphjm`; + +alter table `project_reviewer` + add constraint fk_project_reviewer_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `project_reviewer` + add constraint fk_project_reviewer_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: project_user + +alter table `project_user` drop foreign key `project_user_user_id`; +alter table `project_user` drop foreign key `project_user_project_id`; + +alter table `project_user` drop key `project_user_project_id`; + +alter table `project_user` change `user_id` `user_id` bigint(20) not null after `project_id`; +alter table `project_user` change `reflection` `reflection` text default null after `user_id`; + +alter table `project_user` + add constraint fk_project_user_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `project_user` + add constraint fk_project_user_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: grading_history_submissions + +alter table `grading_history_submissions` drop foreign key `FK_grading_history_submissions_project`; +alter table `grading_history_submissions` drop foreign key `FK_grading_history_submissions_author`; + +alter table `grading_history_submissions` drop key `FK_grading_history_submissions_project`; +alter table `grading_history_submissions` drop key `FK_grading_history_submissions_author`; + +rename table `grading_history_submissions` to `grading_history_submission`; + +alter table `grading_history_submission` change `when` `when` timestamp not null default '0000-00-00 00:00:00' after `id`; +alter table `grading_history_submission` change `corrections` `corrections` text default null after `when`; +alter table `grading_history_submission` change `author_id` `author_user_id` bigint(20) not null after `corrections`; + +alter table `grading_history_submission` + add constraint fk_grading_history_submission_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `grading_history_submission` + add constraint fk_grading_history_submission_author_user_id + foreign key (author_user_id) references user (id) + on delete cascade on update cascade; + +-- table: externallink + +alter table `externallink` drop foreign key `FK_PROJECT`; +alter table `externallink` drop foreign key `FK_USER`; + +alter table `externallink` drop key `FK_PROJECT`; +alter table `externallink` drop key `FK_USER`; + +rename table `externallink` to `external_link`; + +alter table `external_link` change `description` `description` varchar(255) default null after `url`; + +alter table `external_link` + add constraint fk_external_link_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `external_link` + add constraint fk_external_link_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: grade + +alter table `grade` drop foreign key `FK_grade_user_reportedBy`; +alter table `grade` drop foreign key `FK_grade_project`; + +alter table `grade` drop key `FK_grade_user_reportedBy`; +alter table `grade` drop key `project_id`; + +alter table `grade` change `value` `value` varchar(255) not null after `id`; +alter table `grade` change `reportedOn` `reported_when` date not null after `value`; +alter table `grade` change `project_id` `project_id` bigint(20) not null after `reported_when`; +alter table `grade` change `reportedBy` `reported_by_user_id` bigint(20) not null after `project_id`; + +alter table `grade` add constraint uk_grade_project_id unique(project_id); + +alter table `grade` + add constraint fk_grade_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `grade` + add constraint fk_grade_reported_by_user_id + foreign key (reported_by_user_id) references user (id) + on delete cascade on update cascade; + +/* + * Step 17: file_reference & file_description, FinalThesis and project_file + */ + +-- table: file_description + +alter table `file_description` drop foreign key `file_description_user`; + +alter table `file_description` drop key `file_description_user`; +alter table `file_description` drop key `file_description_identifier_index`; + +alter table `file_description` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `file_description` change `name` `name` varchar(255) default null after `version`; +alter table `file_description` change `mimeType` `mime_type` varchar(255) default null after `name`; +alter table `file_description` change `size` `size` bigint(20) default null after `mime_type`; +alter table `file_description` change `identifier` `file_identifier` varchar(255) default null after `size`; +alter table `file_description` change `type` `type` varchar(255) default null after `file_identifier`; +alter table `file_description` change `userId` `user_id` bigint(20) default null after `type`; + +alter table `file_description` + add constraint fk_file_description_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: file_reference + +alter table file_reference drop foreign key `FK_file_reference_file_description`; + +alter table file_reference drop key `FK_file_reference_file_description`; + +alter table file_reference + add constraint fk_file_reference_file_description_id + foreign key (file_description_id) references file_description (id) + on delete cascade on update cascade; + +-- table: FinalThesis + +alter table FinalThesis drop foreign key `FK_final_thesis_text_matching_document_reference`; +alter table FinalThesis drop foreign key `FK_final_thesis_project`; +alter table FinalThesis drop foreign key `FK_final_thesis_document_reference`; + +alter table FinalThesis drop key `FK_final_thesis_text_matching_document_reference`; +alter table FinalThesis drop key `FK_final_thesis_project`; + +rename table FinalThesis to `final_thesis`; + +alter table `final_thesis` change `swedishTitle` `title_sv` longtext default null after `version`; +alter table `final_thesis` change `englishTitle` `title_en` longtext default null after `title_sv`; +alter table `final_thesis` change `status` `status` varchar(32) not null after `title_en`; +alter table `final_thesis` change `dateApproved` `date_approved` date default null after `status`; +alter table `final_thesis` change `dateRejected` `date_rejected` date default null after `date_approved`; +alter table `final_thesis` change `rejection_comment` `rejection_comment` text default null after `date_rejected`; +alter table `final_thesis` change `text_matching_analysis` `text_matching_analysis` text default null after `rejection_comment`; +alter table `final_thesis` change `text_matching_document_reference_id` `text_matching_document_reference_id` bigint(20) default null after `text_matching_analysis`; +alter table `final_thesis` change `project_id` `project_id` bigint(20) not null after `document_reference_id`; + +alter table `final_thesis` + add constraint fk_final_thesis_text_matching_document_reference_id + foreign key (text_matching_document_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `final_thesis` + add constraint fk_final_thesis_document_reference_id + foreign key (document_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `final_thesis` + add constraint fk_final_thesis_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- table: project_file + +alter table `project_file` drop foreign key FK_project_file_project; +alter table `project_file` drop foreign key FK_project_file_file; + +alter table `project_file` drop key FK_project_file_file; +alter table `project_file` drop key FK_project_file_project; + +alter table `project_file` change `fileSource` `file_source` varchar(255) not null after `version`; +alter table `project_file` change `project_id` `project_id` bigint(20) not null after `file_reference_id`; + +alter table `project_file` + add constraint fk_project_file_file_reference_id + foreign key (file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `project_file` + add constraint fk_project_file_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +/* + * Step 18: Decision & ReviewerApproval + */ + +-- table: Decision + +alter table `Decision` drop foreign key `fk_Decision_ReviewerApproval`; +alter table `Decision` drop foreign key `FK_decision_reviewer`; +alter table `Decision` drop foreign key `FK_Decision_thesis`; +alter table `Decision` drop foreign key `FK_Decision_attachment`; + +alter table `Decision` drop key `FK_decision_reviewer`; +alter table `Decision` drop key `FK_Decision_attachment`; +alter table `Decision` drop key `FK_Decision_thesis`; +alter table `Decision` drop key `fk_ReviewerApproval_Decision_idx`; + +rename table `Decision` to `decision`; + +alter table `decision` change `status` `status` varchar(255) default null after `id`; +alter table `decision` change `requested` `requested_date` datetime not null; +alter table `decision` change `decisionDate` `decision_date` datetime default null; +alter table `decision` change `deadline` `deadline` datetime default null after `decision_date`; +alter table `decision` change `assigned_reviewer_date` `assigned_reviewer_date` date default null after `deadline`; +alter table `decision` change `assigned_reviewer_id` `assigned_reviewer_id` bigint(20) default null after `assigned_reviewer_date`; +alter table `decision` change `attachment_reference_id` `attachment_reference_id` bigint(20) default null after `assigned_reviewer_id`; +alter table `decision` change `reviewerApproval_id` `reviewer_approval_id` bigint(20) not null; + +alter table `decision` + add constraint fk_decision_assigned_reviewer_id + foreign key (assigned_reviewer_id) references user (id) + on delete cascade on update cascade; + +alter table `decision` + add constraint fk_decision_attachment_reference_id + foreign key (attachment_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `decision` + add constraint fk_decision_thesis_reference_id + foreign key (thesis_reference_id) references file_reference (id) + on delete cascade on update cascade; + +-- table: ReviewerApproval + +alter table `ReviewerApproval` drop foreign key `FK_9lr1dn8boyfc5a0477ld4q8rw`; + +alter table `ReviewerApproval` drop key `FK_9lr1dn8boyfc5a0477ld4q8rw`; + +rename table `ReviewerApproval` to `reviewer_approval`; + +alter table `reviewer_approval` change `type` `type` varchar(64) not null after `version`; +alter table `reviewer_approval` change `project_id` `project_id` bigint(20) not null after `type`; + +alter table `reviewer_approval` + add constraint fk_reviewer_approval_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +-- add foreign key from decision to reviewer_approval + +alter table `decision` + add constraint fk_decision_reviewer_approval_id + foreign key (reviewer_approval_id) references reviewer_approval (id) + on delete cascade on update cascade; + +/* + * Step 19: urkund_submission & plagiarium_request + */ + +-- table: urkund_submission + +alter table `urkund_submission` drop foreign key `FK_urkund_submission_receiver`; +alter table `urkund_submission` drop foreign key `FK_urkund_submission_document_reference`; + +alter table `urkund_submission` drop key `FK_urkund_submission_document_reference`; +alter table `urkund_submission` drop key `FK_urkund_submission_receiver`; + +alter table `urkund_submission` change `document_reference_id` `document_file_reference_id` bigint(20) not null; +alter table `urkund_submission` change `receiver_id` `receiver_user_id` bigint(20) not null after `document_file_reference_id`; +alter table `urkund_submission` change `submitted` `submitted_date` datetime not null; +alter table `urkund_submission` change `nextPoll` `next_poll_date` datetime not null; +alter table `urkund_submission` change `pollingDelay` `polling_delay` varchar(16) not null; +alter table `urkund_submission` change `reportUrl` `report_url` varchar(255) default null; +alter table `urkund_submission` change `analysisAddress` `analysis_address` varchar(255) default null; + +alter table `urkund_submission` + add constraint fk_urkund_submission_document_file_reference_id + foreign key (document_file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `urkund_submission` + add constraint fk_urkund_submission_receiver_user_id + foreign key (receiver_user_id) references user (id) + on delete cascade on update cascade; + +-- table: plagiarism_request + +alter table `plagiarism_request` drop foreign key `FK_plagiarism_request_receiver`; +alter table `plagiarism_request` drop foreign key `FK_plagiarism_request_document_reference`; + +alter table `plagiarism_request` drop key `FK_plagiarism_request_document_reference`; +alter table `plagiarism_request` drop key `FK_plagiarism_request_receiver`; + +alter table `plagiarism_request` change `document_reference_id` `document_file_reference_id` bigint(20) not null; +alter table `plagiarism_request` change `receiver_id` `receiver_user_id` bigint(20) not null after `document_file_reference_id`; + +alter table `plagiarism_request` + add constraint fk_plagiarism_request_document_file_reference_id + foreign key (document_file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +alter table `plagiarism_request` + add constraint fk_plagiarism_request_receiver_user_id + foreign key (receiver_user_id) references user (id) + on delete cascade on update cascade; + +/* + * Step 20: mail_event, mail_event_recipients and MailEvent_nonUserRecipients + */ + +-- table: mail_event + +alter table `mail_event` drop foreign key `FK_mail_event_attachment`; + +alter table `mail_event` drop key `FK_mail_event_attachment`; + +alter table `mail_event` change `version` `version` int(4) not null default 0 after `last_modified`; +alter table `mail_event` change `subject` `subject` varchar(255) not null after `version`; +alter table `mail_event` change `fromName` `from_name` varchar(255) default null after `subject`; +alter table `mail_event` change `fromEmail` `from_email` varchar(255) default null after `from_name`; +alter table `mail_event` change `messageBody` `message_body` longtext not null after `from_email`; +alter table `mail_event` change `sent` `sent` tinyint(1) not null default 0 after `message_body`; +alter table `mail_event` change `messageID` `message_id` varchar(255) default null after `sent`; +alter table `mail_event` change `notificationEventType` `notification_event_type` varchar(255) default null after `message_id`; +alter table `mail_event` change `attachment_reference_id` `attachment_file_reference_id` bigint(20) default null after `notification_event_type`; + +alter table `mail_event` + add constraint fk_mail_event_attachment_file_reference_id + foreign key (attachment_file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +-- table: mail_event_recipients + +alter table `mail_event_recipients` drop foreign key `FK_mail_event_recipients_user`; +alter table `mail_event_recipients` drop foreign key `FK41091C7FE7F98C6`; + +alter table `mail_event_recipients` drop key `FK41091C7B286D1B0`; +alter table `mail_event_recipients` drop key `FK41091C7FE7F98C6`; + +alter table `mail_event_recipients` drop primary key; + +rename table `mail_event_recipients` to `mail_event_recipient`; + +alter table `mail_event_recipient` change `recipients_id` `recipient_id` bigint(20) not null after `mail_event_id`; + +alter table `mail_event_recipient` add primary key (mail_event_id, recipient_id); + +alter table `mail_event_recipient` + add constraint fk_mail_event_recipient_mail_event_id + foreign key (mail_event_id) references mail_event (id) + on delete cascade on update cascade; + +alter table `mail_event_recipient` + add constraint fk_mail_event_recipient_recipient_id + foreign key (recipient_id) references user (id) + on delete cascade on update cascade; + +-- table: MailEvent_nonUserRecipients + +alter table `MailEvent_nonUserRecipients` drop foreign key `FKD7F8996D0814DF5`; +alter table `MailEvent_nonUserRecipients` drop key `FKD7F8996D0814DF5`; + +rename table `MailEvent_nonUserRecipients` to `mail_event_non_user_recipient`; + +alter table `mail_event_non_user_recipient` change `MailEvent_id` `mail_event_id` bigint(20) not null; +alter table `mail_event_non_user_recipient` change `nonUserRecipients` `non_user_recipient` varchar(255) default null; + +alter table `mail_event_non_user_recipient` + add constraint fk_mail_event_non_user_recipient_mail_event_id + foreign key (mail_event_id) references mail_event (id) + on delete cascade on update cascade; + +/* + * Step 21: project_group and project_group_project + */ + +-- table: project_group + +alter table `project_group` drop foreign key `FK_user_id`; +alter table `project_group` drop key `FK_user_id`; + +alter table `project_group` change `active` `active` bit(1) not null after `description`; + +alter table `project_group` + add constraint fk_project_group_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: project_group_project + +alter table `project_group_project` drop foreign key `FK_project_id`; +alter table `project_group_project` drop foreign key `FK_project_group_id`; + +alter table `project_group_project` drop key `FK_project_id`; +alter table `project_group_project` drop key `FK_project_group_id`; + +alter table `project_group_project` + add constraint fk_project_group_project_project_group_id + foreign key (project_group_id) references project_group (id) + on delete cascade on update cascade; + +alter table `project_group_project` + add constraint fk_project_group_project_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +/* + * Step 22: thread, forum_post and forum_post_file_description + */ + +-- table: thread + +alter table `thread` change `deleted` `deleted` tinyint(1) not null after `subject`; + +-- table: forum_post + +alter table `forum_post` drop foreign key `forum_posts_thread`; +alter table `forum_post` drop foreign key `FKEDDC4F35924F477B`; + +alter table `forum_post` drop key `deleted_index`; +alter table `forum_post` drop key `FKEDDC4F355E9380A1`; +alter table `forum_post` drop key `FKEDDC4F35924F477B`; + +alter table `forum_post` change `content` `content` longtext not null after `version`; +alter table `forum_post` change `thread` `thread_id` bigint(20) not null after `deleted`; +alter table `forum_post` change `user` `user_id` bigint(20) default null after `thread_id`; + +create index idx_forum_post_deleted on forum_post (deleted); + +alter table `forum_post` + add constraint fk_forum_post_thread_id + foreign key (thread_id) references thread (id) + on delete cascade on update cascade; + +alter table `forum_post` + add constraint fk_forum_post_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: forum_post_file_description + +alter table `forum_post_file_description` drop foreign key `FK_forum_post_file`; + +alter table `forum_post_file_description` drop key `I_forum_post_file_post`; +alter table `forum_post_file_description` drop key `FK_forum_post_file`; + +rename table `forum_post_file_description` to `forum_post_file_reference`; + +alter table `forum_post_file_reference` + add constraint fk_forum_post_file_reference_forum_post_id + foreign key (forum_post_id) references forum_post (id) + on delete cascade on update cascade; + +alter table `forum_post_file_reference` + add constraint fk_forum_post_file_reference_file_reference_id + foreign key (file_reference_id) references file_reference (id) + on delete cascade on update cascade; + +/* + * Step 23: forum_post_read, project_thread, reviewer_thread and group_thread + */ + +-- table: forum_post_read + +alter table `forum_post_read` drop foreign key `FK8A5DFC60DD74550D`; +alter table `forum_post_read` drop foreign key `FK8A5DFC60924F477B`; + +alter table `forum_post_read` drop key `FK8A5DFC60DD74550D`; +alter table `forum_post_read` drop key `FK8A5DFC60924F477B`; + +alter table `forum_post_read` drop primary key; + +rename table `forum_post_read` to `forum_post_read_state`; + +alter table `forum_post_read_state` change `read` `read` tinyint(1) not null after `post`; +alter table `forum_post_read_state` change `user` `user_id` bigint(20) not null after `post`; +alter table `forum_post_read_state` change `post` `forum_post_id` bigint(20) not null; + +alter table `forum_post_read_state` add primary key (forum_post_id, user_id); + +alter table `forum_post_read_state` + add constraint fk_forum_post_read_state_forum_post_id + foreign key (forum_post_id) references forum_post (id) + on delete cascade on update cascade; + +alter table `forum_post_read_state` + add constraint fk_forum_post_read_state_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: project_thread + +alter table `project_thread` drop foreign key `FK_project_thread_thread`; +alter table `project_thread` drop foreign key `FK_project_thread_project`; + +alter table `project_thread` drop key `FK_project_thread_thread`; +alter table `project_thread` drop key `FK_project_thread_project`; + +alter table `project_thread` change `project_id` `project_id` bigint(20) not null after `id`; + +alter table `project_thread` + add constraint fk_project_thread_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `project_thread` + add constraint fk_project_thread_thread_id + foreign key (thread_id) references thread (id) + on delete cascade on update cascade; + +-- table: reviewer_thread + +alter table `reviewer_thread` drop foreign key `FK_reviewer_thread_thread`; +alter table `reviewer_thread` drop foreign key `FK_reviewer_thread_group`; + +alter table `reviewer_thread` drop key `FK_reviewer_thread_thread`; +alter table `reviewer_thread` drop key `project_id`; + +alter table `reviewer_thread` change `thread_id` `thread_id` bigint(20) not null after `project_id`; + +alter table `reviewer_thread` add constraint uk_reviewer_thread_project_id unique(project_id, thread_id); + +alter table `reviewer_thread` + add constraint fk_reviewer_thread_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `reviewer_thread` + add constraint fk_reviewer_thread_thread_id + foreign key (thread_id) references thread (id) + on delete cascade on update cascade; + +-- table: group_thread + +alter table `group_thread` drop foreign key `FK_project_group_thread_thread`; +alter table `group_thread` drop foreign key `FK_project_group_thread_group`; + +alter table `group_thread` drop key `FK_project_group_thread_thread`; +alter table `group_thread` drop key `project_group`; + +rename table `group_thread` to `project_group_thread`; + +alter table `project_group_thread` change `group_id` `project_group_id` bigint(20) not null after `id`; + +alter table `project_group_thread` + add constraint fk_project_group_thread_project_group_id + foreign key (project_group_id) references project_group (id) + on delete cascade on update cascade; + +alter table `project_group_thread` + add constraint fk_project_group_thread_thread_id + foreign key (thread_id) references thread (id) + on delete cascade on update cascade; + +/* + * Step 24: forum_notification, Notification, NotificationData + */ + +-- table: forum_notification, + +alter table `forum_notification` drop foreign key `FK_forum_notification_notification_event`; +alter table `forum_notification` drop foreign key `FK_forum_notification_forum_post`; + +alter table `forum_notification` drop key `FK_forum_notification_notification_event`; + +alter table `forum_notification` drop primary key; + +alter table `forum_notification` change `forumPost_id` `forum_post_id` bigint(20) not null; +alter table `forum_notification` change `notificationEvent_id` `notification_data_id` bigint(20) not null; + +alter table `forum_notification` add primary key (forum_post_id, notification_data_id); + +alter table `forum_notification` + add constraint fk_forum_notification_forum_post_id + foreign key (forum_post_id) references forum_post (id) + on delete cascade on update cascade; + +-- table: Notification + +alter table `Notification` drop foreign key `FK_notification_user`; +alter table `Notification` drop foreign key `FK2D45DD0B599425F6`; + +alter table `Notification` drop key `FK2D45DD0B599425F6`; +alter table `Notification` drop key `FK2D45DD0B895349BF`; + +rename table `Notification` to `notification`; + +alter table `notification` change `mailed` `mailed` bit(1) not null after `version`; +alter table `notification` change `notificationData_id` `notification_data_id` bigint(20) default null; + +alter table `notification` + add constraint fk_notification_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + +-- table: NotificationData + +alter table `NotificationData` drop foreign key `FK_notification_data_user_caused_by`; +alter table `NotificationData` drop foreign key `FK_notification_data_project`; +alter table `NotificationData` drop foreign key `FK_notification_data_peer_review`; +alter table `NotificationData` drop foreign key `FK_notification_data_milestone`; +alter table `NotificationData` drop foreign key `FK_notification_data_group`; +alter table `NotificationData` drop foreign key `FK2DCAC355FCDADF61`; +alter table `NotificationData` drop foreign key `FK2DCAC3558D40D1B9`; +alter table `NotificationData` drop foreign key `FK2DCAC3554D07E0A9`; + +alter table `NotificationData` drop key `FK_notification_data_group`; +alter table `NotificationData` drop key `FK_notification_data_milestone`; +alter table `NotificationData` drop key `FK2DCAC355FCDADF61`; +alter table `NotificationData` drop key `FK2DCAC355B2E2AD78`; +alter table `NotificationData` drop key `FK2DCAC3558D40D1B9`; +alter table `NotificationData` drop key `FK2DCAC35542E9AC7B`; +alter table `NotificationData` drop key `FK2DCAC355C1813915`; +alter table `NotificationData` drop key `FK2DCAC3554D07E0A9`; + +rename table `NotificationData` to `notification_data`; + +alter table `notification_data` change `type` `type` varchar(255) default null after `event`; +alter table `notification_data` change `source` `source` longtext default null after `type`; +alter table `notification_data` change `additionalSource` `additional_source` longtext default null after `source`; +alter table `notification_data` change `DTYPE` `subclass` varchar(31) not null after `additional_source`; + +alter table `notification_data` change `seminar_id` `final_seminar_id` bigint(20) default null after `subclass`; +alter table `notification_data` change `idea_id` `idea_id` bigint(20) default null after `final_seminar_id`; +alter table `notification_data` change `mileStone_id` `milestone_id` bigint(20) default null after `idea_id`; +alter table `notification_data` change `request_id` `peer_request_id` bigint(20) default null after `milestone_id`; +alter table `notification_data` change `review_id` `peer_review_id` bigint(20) default null after `peer_request_id`; +alter table `notification_data` change `project_id` `project_id` bigint(20) default null after `peer_review_id`; +alter table `notification_data` change `group_id` `project_group_id` bigint(20) default null after `project_id`; +alter table `notification_data` change `causedBy_id` `caused_by_user_id` bigint(20) default null after `project_group_id`; + +alter table `notification_data` + add constraint fk_notification_data_final_seminar_id + foreign key (final_seminar_id) references final_seminar (id) + on delete cascade on update cascade; + +alter table `notification_data` + add constraint fk_notification_data_idea_id + foreign key (idea_id) references idea (id) + on delete cascade on update cascade; + +alter table `notification_data` + add constraint fk_notification_data_milestone_id + foreign key (milestone_id) references milestone (id) + on delete cascade on update cascade; + +alter table `notification_data` + add constraint fk_notification_data_peer_request_id + foreign key (peer_request_id) references peer_request (id) + on delete set null on update cascade; + +alter table `notification_data` + add constraint fk_notification_data_peer_review_id + foreign key (peer_review_id) references peer_review (id) + on delete cascade on update cascade; + +alter table `notification_data` + add constraint fk_notification_data_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; + +alter table `notification_data` + add constraint fk_notification_data_project_group_id + foreign key (project_group_id) references project_group (id) + on delete cascade on update cascade; + +alter table `notification_data` + add constraint fk_notification_data_caused_by_user_id + foreign key (caused_by_user_id) references user (id) + on delete set null on update cascade; + +-- add foreign key from notification to notification_data + +alter table `notification` + add constraint fk_notification_notification_data_id + foreign key (notification_data_id) references notification_data (id) + on delete cascade on update cascade; + +-- add foreign key from forum_notification to notification_data + +alter table `forum_notification` + add constraint fk_forum_notification_notification_data_id + foreign key (notification_data_id) references notification_data (id) + on delete cascade on update cascade; diff --git a/core/src/test/java/se/su/dsv/scipro/milestones/service/MilestoneActivatorTest.java b/core/src/test/java/se/su/dsv/scipro/milestones/service/MilestoneActivatorTest.java index e42ccafdfc..fed52e8629 100644 --- a/core/src/test/java/se/su/dsv/scipro/milestones/service/MilestoneActivatorTest.java +++ b/core/src/test/java/se/su/dsv/scipro/milestones/service/MilestoneActivatorTest.java @@ -66,7 +66,7 @@ public class MilestoneActivatorTest { author.setId(123L); ProjectType bachelor = new ProjectType(DegreeType.BACHELOR, "Bachelor", "Bachelor"); - bachelor.getProjectTypeSettings().setMinimumActiveParticipationsToBeGraded(2); + bachelor.getProjectTypeSettings().setMinActiveParticipationsToBeGraded(2); project = Project.builder() .title("Project title") .projectType(bachelor) diff --git a/view/src/main/java/se/su/dsv/scipro/admin/panels/AdminProjectTypePanel.java b/view/src/main/java/se/su/dsv/scipro/admin/panels/AdminProjectTypePanel.java index ad084a3436..8284ab8966 100755 --- a/view/src/main/java/se/su/dsv/scipro/admin/panels/AdminProjectTypePanel.java +++ b/view/src/main/java/se/su/dsv/scipro/admin/panels/AdminProjectTypePanel.java @@ -54,16 +54,16 @@ public class AdminProjectTypePanel extends Panel { NumberTextField minimumOppositionsToBeGraded = new NumberTextField<>( "minimum_oppositions_to_be_graded", LambdaModel.of(settings, - ProjectTypeSettings::getMinimumOppositionsToBeGraded, - ProjectTypeSettings::setMinimumOppositionsToBeGraded), + ProjectTypeSettings::getMinOppositionsToBeGraded, + ProjectTypeSettings::setMinOppositionsToBeGraded), Integer.class); minimumOppositionsToBeGraded.setMinimum(0); add(minimumOppositionsToBeGraded); NumberTextField minimumActiveParticipationsToBeGraded = new NumberTextField<>( "minimum_active_participations_to_be_graded", LambdaModel.of(settings, - ProjectTypeSettings::getMinimumActiveParticipationsToBeGraded, - ProjectTypeSettings::setMinimumActiveParticipationsToBeGraded), + ProjectTypeSettings::getMinActiveParticipationsToBeGraded, + ProjectTypeSettings::setMinActiveParticipationsToBeGraded), Integer.class); minimumActiveParticipationsToBeGraded.setMinimum(0); add(minimumActiveParticipationsToBeGraded); diff --git a/view/src/main/java/se/su/dsv/scipro/checklists/AnswerPanel.java b/view/src/main/java/se/su/dsv/scipro/checklists/AnswerPanel.java index 5e54b3e4a9..a300022d1b 100644 --- a/view/src/main/java/se/su/dsv/scipro/checklists/AnswerPanel.java +++ b/view/src/main/java/se/su/dsv/scipro/checklists/AnswerPanel.java @@ -27,7 +27,7 @@ public abstract class AnswerPanel extends Panel { ANSWER_IMAGES.put(ChecklistAnswerEnum.GREEN, "images/icons/bullet_ball_glass_green.png"); ANSWER_IMAGES.put(ChecklistAnswerEnum.YELLOW, "images/icons/bullet_ball_glass_yellow.png"); ANSWER_IMAGES.put(ChecklistAnswerEnum.RED, "images/icons/bullet_ball_glass_red.png"); - ANSWER_IMAGES.put(ChecklistAnswerEnum.NOT_APLICABLE, "images/icons/bullet_ball_glass_grey.png"); + ANSWER_IMAGES.put(ChecklistAnswerEnum.NOT_APPLICABLE, "images/icons/bullet_ball_glass_grey.png"); } public static final String CLICK_ICON = "images/icons/bullet_ball_glass_click.png"; diff --git a/view/src/main/java/se/su/dsv/scipro/checklists/ChecklistOverviewPanel.java b/view/src/main/java/se/su/dsv/scipro/checklists/ChecklistOverviewPanel.java index 1af096eee2..250d82e7e7 100644 --- a/view/src/main/java/se/su/dsv/scipro/checklists/ChecklistOverviewPanel.java +++ b/view/src/main/java/se/su/dsv/scipro/checklists/ChecklistOverviewPanel.java @@ -55,7 +55,7 @@ public class ChecklistOverviewPanel extends GenericPanel { ChecklistAnswerEnum.GREEN, ChecklistAnswerEnum.YELLOW, ChecklistAnswerEnum.RED, - ChecklistAnswerEnum.NOT_APLICABLE); + ChecklistAnswerEnum.NOT_APPLICABLE); add(new ListView<>("answersBreakdown", answers) { @Override protected void populateItem(ListItem item) { diff --git a/view/src/main/java/se/su/dsv/scipro/checklists/ChecklistOverviewPanel.utf8.properties b/view/src/main/java/se/su/dsv/scipro/checklists/ChecklistOverviewPanel.utf8.properties index 9ad8928894..0d30f3ea89 100644 --- a/view/src/main/java/se/su/dsv/scipro/checklists/ChecklistOverviewPanel.utf8.properties +++ b/view/src/main/java/se/su/dsv/scipro/checklists/ChecklistOverviewPanel.utf8.properties @@ -1,4 +1,4 @@ ChecklistAnswerEnum.GREEN = Ok ChecklistAnswerEnum.YELLOW = Minor corrections ChecklistAnswerEnum.RED = Not done -ChecklistAnswerEnum.NOT_APLICABLE = Not applicable +ChecklistAnswerEnum.NOT_APPLICABLE = Not applicable diff --git a/view/src/main/java/se/su/dsv/scipro/checklists/TrafficLightPanel.java b/view/src/main/java/se/su/dsv/scipro/checklists/TrafficLightPanel.java index 51e779ba99..60482c38a8 100644 --- a/view/src/main/java/se/su/dsv/scipro/checklists/TrafficLightPanel.java +++ b/view/src/main/java/se/su/dsv/scipro/checklists/TrafficLightPanel.java @@ -54,7 +54,7 @@ public class TrafficLightPanel extends FormComponentPanel { greenLink = new TrafficLightLink("greenLink", ChecklistAnswerEnum.GREEN, selectedGreen, greenImage); redLink = new TrafficLightLink("redLink", ChecklistAnswerEnum.RED, selectedRed, redImage); yellowLink = new TrafficLightLink("yellowLink", ChecklistAnswerEnum.YELLOW, selectedYellow, yellowImage); - noAnswerLink = new TrafficLightLink("noAnswerLink", ChecklistAnswerEnum.NOT_APLICABLE, selectedNotApplicable, noAnswerImage); + noAnswerLink = new TrafficLightLink("noAnswerLink", ChecklistAnswerEnum.NOT_APPLICABLE, selectedNotApplicable, noAnswerImage); add(greenLink); add(yellowLink); add(redLink); diff --git a/view/src/main/java/se/su/dsv/scipro/finalseminar/ProjectActiveParticipationListPanel.java b/view/src/main/java/se/su/dsv/scipro/finalseminar/ProjectActiveParticipationListPanel.java index 158b6ec5d9..40bb5744a8 100644 --- a/view/src/main/java/se/su/dsv/scipro/finalseminar/ProjectActiveParticipationListPanel.java +++ b/view/src/main/java/se/su/dsv/scipro/finalseminar/ProjectActiveParticipationListPanel.java @@ -36,7 +36,7 @@ public class ProjectActiveParticipationListPanel extends GenericPanel { IModel countRequired = model .map(Project::getProjectType) .map(ProjectType::getProjectTypeSettings) - .map(ProjectTypeSettings::getMinimumActiveParticipationsToBeGraded); + .map(ProjectTypeSettings::getMinActiveParticipationsToBeGraded); item.add(new Label("count_required", countRequired)); IModel countPerformed = participations.map(this::countApproved); item.add(new Label("count_approved", countPerformed)); diff --git a/view/src/main/java/se/su/dsv/scipro/grading/AbstractExaminationsPanel.java b/view/src/main/java/se/su/dsv/scipro/grading/AbstractExaminationsPanel.java index fbf8b36a5f..f24d065eb0 100644 --- a/view/src/main/java/se/su/dsv/scipro/grading/AbstractExaminationsPanel.java +++ b/view/src/main/java/se/su/dsv/scipro/grading/AbstractExaminationsPanel.java @@ -213,8 +213,8 @@ abstract class AbstractExaminationsPanel extends GenericPanel { .filter(FinalSeminarActiveParticipation::isApproved) .count(); final ProjectTypeSettings projectTypeSettings = project.getProjectType().getProjectTypeSettings(); - final int requiredOppositions = projectTypeSettings.getMinimumOppositionsToBeGraded(); - final int requiredActiveParticipations = projectTypeSettings.getMinimumActiveParticipationsToBeGraded(); + final int requiredOppositions = projectTypeSettings.getMinOppositionsToBeGraded(); + final int requiredActiveParticipations = projectTypeSettings.getMinActiveParticipationsToBeGraded(); return new SeminarParticipationGradingRequirements( new Requirement(requiredOppositions, completedOppositions), new Requirement(requiredActiveParticipations, completedParticipations)); diff --git a/view/src/main/java/se/su/dsv/scipro/grading/IndividualAuthorAssessmentPanel.java b/view/src/main/java/se/su/dsv/scipro/grading/IndividualAuthorAssessmentPanel.java index d76881782b..6dff147635 100644 --- a/view/src/main/java/se/su/dsv/scipro/grading/IndividualAuthorAssessmentPanel.java +++ b/view/src/main/java/se/su/dsv/scipro/grading/IndividualAuthorAssessmentPanel.java @@ -128,7 +128,7 @@ public class IndividualAuthorAssessmentPanel extends GenericPanel { IModel minimumActiveParticipationsToBeGraded = LoadableDetachableModel.of(() -> { Project project = projectModel.getObject(); - return project.getProjectType().getProjectTypeSettings().getMinimumActiveParticipationsToBeGraded(); + return project.getProjectType().getProjectTypeSettings().getMinActiveParticipationsToBeGraded(); }); IModel completedParticipations = LoadableDetachableModel.of(() -> { Project project = projectModel.getObject(); diff --git a/view/src/main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.java b/view/src/main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.java index 2c6818bb3e..7679a75eba 100644 --- a/view/src/main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.java +++ b/view/src/main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.java @@ -38,7 +38,7 @@ public class DisplayQuestionPanel extends GenericPanel { return "images/icons/bullet_ball_glass_red.png"; case GREEN: return "images/icons/bullet_ball_glass_green.png"; - case NOT_APLICABLE: + case NOT_APPLICABLE: return "images/icons/bullet_ball_glass_grey.png"; default: throw new IllegalStateException("unknown answer"); diff --git a/view/src/main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.properties b/view/src/main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.properties index 83808b9c7e..a2d4ad4158 100644 --- a/view/src/main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.properties +++ b/view/src/main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.properties @@ -2,4 +2,4 @@ no.motivation= No motivation written YELLOW= Minor corrections RED= Not done GREEN= Ok -NOT_APLICABLE= Not applicable \ No newline at end of file +NOT_APPLICABLE= Not applicable \ No newline at end of file diff --git a/view/src/test/java/se/su/dsv/scipro/checklists/TrafficLightPanelTest.java b/view/src/test/java/se/su/dsv/scipro/checklists/TrafficLightPanelTest.java index d8785aca19..b6c0e57856 100644 --- a/view/src/test/java/se/su/dsv/scipro/checklists/TrafficLightPanelTest.java +++ b/view/src/test/java/se/su/dsv/scipro/checklists/TrafficLightPanelTest.java @@ -25,7 +25,7 @@ public class TrafficLightPanelTest extends SciProTest { @Test public void renders_not_applicable() { - startPanel(Model.of(ChecklistAnswerEnum.NOT_APLICABLE)); + startPanel(Model.of(ChecklistAnswerEnum.NOT_APPLICABLE)); } @Test diff --git a/view/src/test/java/se/su/dsv/scipro/peer/DisplayQuestionPanelTest.java b/view/src/test/java/se/su/dsv/scipro/peer/DisplayQuestionPanelTest.java index 56212cd5d9..fbb66e7b45 100644 --- a/view/src/test/java/se/su/dsv/scipro/peer/DisplayQuestionPanelTest.java +++ b/view/src/test/java/se/su/dsv/scipro/peer/DisplayQuestionPanelTest.java @@ -28,7 +28,7 @@ public class DisplayQuestionPanelTest extends SciProTest { @Test public void renders_with_not_applicable_answer() { - startPanel(ChecklistAnswerEnum.NOT_APLICABLE, "motivation"); + startPanel(ChecklistAnswerEnum.NOT_APPLICABLE, "motivation"); } @Test