From 1005534ef7547e806dbecc6e8d26ebbb74db8f62 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 10 Jun 2024 15:07:24 +0200 Subject: [PATCH 01/99] task/3382: Start with two standalone tables, footer_link and worker_data. --- .../java/se/su/dsv/scipro/system/FooterLink.java | 1 + .../se/su/dsv/scipro/workerthreads/WorkerData.java | 4 ++-- .../V388__harmonize_table_attribute_name.sql | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql 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..a26cc08fe1 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/workerthreads/WorkerData.java b/core/src/main/java/se/su/dsv/scipro/workerthreads/WorkerData.java index 4827139331..821e5c81d8 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 @@ -21,10 +21,10 @@ public class WorkerData extends DomainObject { @Column(unique=true, nullable=false) private String name; - @Column(nullable=false) + @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/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql new file mode 100644 index 0000000000..ab0ac4399e --- /dev/null +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -0,0 +1,13 @@ +-- batch 1: standalone tables + +--alter table `plugin_settings` rename `pluginName` to `plugin_name`; + +-- Table: worker_data + +alter table `worker_data` rename `lastRun` to `last_run`; +alter table `worker_data` rename `lastSuccessfulRun` to `last_successful_run`; + +-- alter table `worker_data` rename `dateCreated` to `date_created`; +-- alter table `worker_data` rename `lastModified` to `last_modified`; + +alter table `footer_link` rename `footerColumn` to `footer_column`; \ No newline at end of file -- 2.39.5 From b99c2457b420d49a39590979dd0fde91571d102b Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 10 Jun 2024 15:40:53 +0200 Subject: [PATCH 02/99] task/3382: fix SQL syntax errors. --- .../V388__harmonize_table_attribute_name.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index ab0ac4399e..bc9fef5624 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -1,13 +1,13 @@ --- batch 1: standalone tables +-- Step 1: standalone tables ---alter table `plugin_settings` rename `pluginName` to `plugin_name`; +-- alter table `plugin_settings` rename column `pluginName` to `plugin_name`; -- Table: worker_data -alter table `worker_data` rename `lastRun` to `last_run`; -alter table `worker_data` rename `lastSuccessfulRun` to `last_successful_run`; +alter table `worker_data` rename column `lastRun` to `last_run`; +alter table `worker_data` rename column `lastSuccessfulRun` to `last_successful_run`; --- alter table `worker_data` rename `dateCreated` to `date_created`; --- alter table `worker_data` rename `lastModified` to `last_modified`; +-- alter table `worker_data` rename column `dateCreated` to `date_created`; +-- alter table `worker_data` rename column `lastModified` to `last_modified`; -alter table `footer_link` rename `footerColumn` to `footer_column`; \ No newline at end of file +alter table `footer_link` rename column `footerColumn` to `footer_column`; \ No newline at end of file -- 2.39.5 From c37f3f5b6638c9f973a96331f5d412ec8eb55ab8 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 17 Jun 2024 10:47:47 +0200 Subject: [PATCH 03/99] task/3382: Root object DomainObject maps to date_created and last_modified. --- core/src/main/java/se/su/dsv/scipro/system/DomainObject.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 -- 2.39.5 From d1bc4f225e1a4a2a1394f136b00b6038a449d492 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 17 Jun 2024 10:48:31 +0200 Subject: [PATCH 04/99] task/3382: SQL script update, drop unused tables, fix date_created and last_modified. --- .../V388__harmonize_table_attribute_name.sql | 379 +++++++++++++++++- 1 file changed, 373 insertions(+), 6 deletions(-) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index bc9fef5624..393d9bae73 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -1,13 +1,380 @@ --- Step 1: standalone tables +/* + * Step 1: Remove obsolete tables + */ --- alter table `plugin_settings` rename column `pluginName` to `plugin_name`; +drop table plugin_settings; +drop table turnitincheck; --- Table: worker_data +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`; --- alter table `worker_data` rename column `dateCreated` to `date_created`; --- alter table `worker_data` rename column `lastModified` to `last_modified`; +-- table: footer_link + +alter table `footer_link` rename column `footerColumn` to `footer_column`; + + -alter table `footer_link` rename column `footerColumn` to `footer_column`; \ No newline at end of file -- 2.39.5 From 0d925467ba47e6c4f8b8a7b988bfec0f94298dbb Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 17 Jun 2024 10:53:11 +0200 Subject: [PATCH 05/99] task/3382: Put a space around assignments on annotations. --- .../main/java/se/su/dsv/scipro/system/FooterLink.java | 2 +- .../se/su/dsv/scipro/workerthreads/WorkerData.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) 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 a26cc08fe1..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,7 +13,7 @@ public class FooterLink extends DomainObject { private Long id; @Enumerated(EnumType.STRING) - @Column(name="footer_column") + @Column(name = "footer_column") private FooterColumn footerColumn; @Basic(optional = false) 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 821e5c81d8..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, name="last_run") - private Date lastRun=new Date(); + @Column(nullable = false, name = "last_run") + private Date lastRun = new Date(); - @Column(nullable=false, name="last_successful_run") + @Column(nullable = false, name = "last_successful_run") private Date lastSuccessfulRun; @PreUpdate -- 2.39.5 From eb28f423af8b128f60389a35b285b2ab76b79f09 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 17 Jun 2024 11:10:03 +0200 Subject: [PATCH 06/99] task/3382: Fix table NonWorkDayPeriod and related entity class. --- .../se/su/dsv/scipro/nonworkperiod/NonWorkDayPeriod.java | 9 ++++----- .../migration/V388__harmonize_table_attribute_name.sql | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) 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..5832935a77 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,23 @@ package se.su.dsv.scipro.nonworkperiod; -import jakarta.persistence.GenerationType; +import jakarta.persistence.*; import se.su.dsv.scipro.system.DomainObject; -import jakarta.persistence.Cacheable; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 393d9bae73..ab5532dc71 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -376,5 +376,10 @@ alter table `worker_data` rename column `lastSuccessfulRun` to `last_successful_ 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`; -- 2.39.5 From a316081b3dfe96617dde442b8de442e548ba8302 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 17 Jun 2024 11:20:04 +0200 Subject: [PATCH 07/99] task/3382: Fix table urkund_settings and related entity class. --- .../su/dsv/scipro/plagiarism/urkund/UrkundSettings.java | 8 +++----- .../db/migration/V388__harmonize_table_attribute_name.sql | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) 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..eacc5dc88b 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,7 @@ package se.su.dsv.scipro.plagiarism.urkund; -import jakarta.persistence.Basic; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; + import java.util.Objects; @Entity @@ -17,7 +15,7 @@ public class UrkundSettings { @Basic private boolean enabled = false; - @Basic + @Column(name = "user_name") private String username; @Basic diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index ab5532dc71..ad6cd2d697 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -383,3 +383,6 @@ alter table `NonWorkDayPeriod` rename column `startDate` to `start_date`; rename table `NonWorkDayPeriod` to `non_work_day_period`; +-- table: urkund_settings + +alter table `urkund_settings` rename column `username` to `user_name`; \ No newline at end of file -- 2.39.5 From ae99973fe743fdab66c210332ede5b87b740699b Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 17 Jun 2024 12:21:52 +0200 Subject: [PATCH 08/99] task/3382: Fix table reviewer_deadline_settings and related entity class. --- .../su/dsv/scipro/reviewing/ReviewerDeadlineSettings.java | 6 +++--- .../db/migration/V388__harmonize_table_attribute_name.sql | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index ad6cd2d697..2d7c3856c3 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -385,4 +385,10 @@ rename table `NonWorkDayPeriod` to `non_work_day_period`; -- table: urkund_settings -alter table `urkund_settings` rename column `username` to `user_name`; \ No newline at end of file +alter table `urkund_settings` rename column `username` to `user_name`; + +-- 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`; \ No newline at end of file -- 2.39.5 From b073cc2db0397965c36160c2a7fde7d4345351d6 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 17 Jun 2024 12:35:30 +0200 Subject: [PATCH 09/99] task/3382: Fix table final_seminar_settings and related entity class. --- .../scipro/finalseminar/FinalSeminarSettings.java | 14 ++++++++------ .../V388__harmonize_table_attribute_name.sql | 14 +++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 2d7c3856c3..d7f35a709b 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -391,4 +391,16 @@ alter table `urkund_settings` rename column `username` to `user_name`; 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`; \ No newline at end of file +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`; \ No newline at end of file -- 2.39.5 From 6e1342ee3b7790db0028b8e54a5ee621a3aee837 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 17 Jun 2024 16:32:52 +0200 Subject: [PATCH 10/99] task/3382: Fix general_system_settings and related tables (3) and entity classes. --- .../GeneralSystemSettings.java | 51 +++++----- .../V388__harmonize_table_attribute_name.sql | 97 ++++++++++++++++++- 2 files changed, 124 insertions(+), 24 deletions(-) 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..21fe2fb803 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") + @Column(name = "system_module") + @CollectionTable(name = "general_system_settings_system_module", + joinColumns = @JoinColumn(name = "general_system_settings_id", referencedColumnName = "id")) 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index d7f35a709b..6e3dabd2bb 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -403,4 +403,99 @@ alter table `FinalSeminarSettings` rename column `thesisMustBePDF` to `thesis_mu 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`; \ No newline at end of file +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 primary key; +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` 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`; + + + + + + + + + + + -- 2.39.5 From d92adb281f27a00558e961f74b7cdf46ec125e56 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 19 Jun 2024 11:00:52 +0200 Subject: [PATCH 11/99] task/3382: Fix table Program and user_program. --- .../java/se/su/dsv/scipro/system/Program.java | 8 ++--- .../V388__harmonize_table_attribute_name.sql | 32 +++++++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) 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..63c2d6acd4 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 @@ -4,7 +4,7 @@ import jakarta.persistence.*; import java.util.Objects; @Entity -@Table(name = "Program") +@Table(name = "program") public class Program extends DomainObject { @Id @@ -12,13 +12,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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 6e3dabd2bb..aaea445eef 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -489,13 +489,39 @@ alter table `general_system_settings` rename column `externalGradingURL` to `ext 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; \ No newline at end of file -- 2.39.5 From 296036ad335a5f0324b6e0e5331beb63027e3477 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 19 Jun 2024 11:53:37 +0200 Subject: [PATCH 12/99] task/3382: Fix foreign key for table note. --- .../V388__harmonize_table_attribute_name.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index aaea445eef..729c9c0dd0 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -521,6 +521,18 @@ alter table `user_program` 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 -- 2.39.5 From 111caa0171554d5184c1970db1197e90db8d96a8 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 19 Jun 2024 15:08:41 +0200 Subject: [PATCH 13/99] task/3382: Apply simple import class. --- .../se/su/dsv/scipro/nonworkperiod/NonWorkDayPeriod.java | 8 +++++++- .../su/dsv/scipro/plagiarism/urkund/UrkundSettings.java | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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 5832935a77..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,6 +1,12 @@ package se.su.dsv.scipro.nonworkperiod; -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 se.su.dsv.scipro.system.DomainObject; import java.time.LocalDate; 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 eacc5dc88b..6301e08f80 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,6 +1,10 @@ package se.su.dsv.scipro.plagiarism.urkund; -import jakarta.persistence.*; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.util.Objects; -- 2.39.5 From 251708adbb5a0be2cd09d74147aa235b5a64ecd4 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 19 Jun 2024 15:10:53 +0200 Subject: [PATCH 14/99] task/3382: Fix table comment & comment_thread and related entity classes. --- core/src/main/java/se/su/dsv/scipro/peer/Comment.java | 2 ++ .../main/java/se/su/dsv/scipro/peer/CommentThread.java | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) 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..d217298107 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 @@ -16,12 +16,14 @@ public class Comment extends DomainObject { private Long id; @ManyToOne(optional = false) + @JoinColumn(name = "user_id") private User creator; @Lob private String comment; @ManyToOne(optional = false) + @JoinColumn(name = "comment_thread_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) -- 2.39.5 From f97c07387ea7571a9d4e2af700176bd33117a846 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 19 Jun 2024 15:22:11 +0200 Subject: [PATCH 15/99] task/3382: Fix table comment & comment_thread - missed sql file. --- .../V388__harmonize_table_attribute_name.sql | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 729c9c0dd0..fde5c2cf6a 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -536,4 +536,36 @@ alter table `note` foreign key (user_id) references user(id) on delete cascade + on update cascade; + +-- table comment & 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 `user_id`; + +alter table `comment` + add constraint fk_comment_user_id + foreign key (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; \ No newline at end of file -- 2.39.5 From 76015ef660e54d7d3e01e020ec3743c0703e58a7 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 19 Jun 2024 15:44:55 +0200 Subject: [PATCH 16/99] task/3382: Fix table reviewer_target and related entity class. --- .../dsv/scipro/reviewing/ReviewerTarget.java | 3 +-- .../V388__harmonize_table_attribute_name.sql | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) 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..2620dea69d 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 @@ -10,7 +10,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 @@ -21,7 +20,7 @@ public class ReviewerTarget extends DomainObject { private Long id; @ManyToOne(optional = false) - @JoinColumn(name = "reviewer_id", nullable = false) + @JoinColumn(name = "user_id", nullable = false) private User reviewer; @Column(name = "year", nullable = false) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index fde5c2cf6a..6922e80f36 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -568,4 +568,24 @@ alter table `comment` foreign key (comment_thread_id) references comment_thread(id) on delete cascade - on update cascade; \ No newline at end of file + 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 `user_id`; + +alter table `reviewer_target` add constraint uk_reviewer_target_user_id_year unique(user_id, year); + +alter table `reviewer_target` + add constraint fk_reviewer_target_user_id + foreign key (user_id) + references user(id) + on delete cascade + on update cascade; + + +NIQUE KEY `UK_ReviewerTarget_ReviewerId_Year` (`reviewer_id`,`year`), + CONSTRAINT `FK_ReviewerTarget_ReviewerId` FOREIGN KEY (`reviewer_id`) REFERENCES `user` (`id`) -- 2.39.5 From 0f28cb10bc6d2a9b7c0029cccb2931a662d6c64c Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 19 Jun 2024 15:54:38 +0200 Subject: [PATCH 17/99] task/3382: Fix table notification_delivery_configuration and it's entity class. --- .../settings/entities/DeliveryConfiguration.java | 2 +- .../V388__harmonize_table_attribute_name.sql | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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..ee89bcf5e9 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 @@ -8,7 +8,7 @@ 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 6922e80f36..498d3495d0 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -586,6 +586,17 @@ alter table `reviewer_target` on delete cascade on update cascade; +-- table: notification_delivery_configuration -NIQUE KEY `UK_ReviewerTarget_ReviewerId_Year` (`reviewer_id`,`year`), - CONSTRAINT `FK_ReviewerTarget_ReviewerId` FOREIGN KEY (`reviewer_id`) REFERENCES `user` (`id`) +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; \ No newline at end of file -- 2.39.5 From eea38b742f0b8376b752f3a04933fab4069fd2ba Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 20 Jun 2024 12:30:44 +0200 Subject: [PATCH 18/99] task73382: Fix table user_name and it's entity class. --- .../se/su/dsv/scipro/system/Username.java | 4 +- .../V388__harmonize_table_attribute_name.sql | 73 ++++++++++++++++++- 2 files changed, 74 insertions(+), 3 deletions(-) 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..9ea10e3f0c 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 @@ -5,13 +5,13 @@ import java.util.Objects; @Entity @Cacheable(true) -@Table(name="username", uniqueConstraints={@UniqueConstraint(columnNames={"username"})}) +@Table(name="user_name", uniqueConstraints={@UniqueConstraint(name = "uk_user_name", columnNames={"user_name"})}) public class Username extends DomainObject { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Basic(optional=false) + @Column(name = "user_name", nullable = false) private String username; @ManyToOne(optional=false) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 498d3495d0..badcca6b21 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -599,4 +599,75 @@ alter table `notification_delivery_configuration` foreign key (user_id) references user(id) on delete cascade - on update cascade; \ No newline at end of file + 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`; + +rename table `username` to `user_name`; + +alter table `user_name` rename column `username` to `user_name`; + +alter table `user_name` add constraint uk_user_name unique(user_name); + +alter table `user_name` + add constraint fk_user_name_user_id + foreign key (user_id) + references user(id) + on delete cascade + on update cascade; + + +/* the mess with ProjectType + + SQL query for FK-to: + + select table_name, column_name, referenced_table_name, referenced_column_name + from key_column_usage + where table_schema = 'tozh4728' and + referenced_table_name = 'ProjectType'; + + select referenced_table_name, count(*) as c + from key_column_usage + where table_schema = 'tozh4728' and + referenced_table_name is not null + group by referenced_table_name order by c desc; + + SQL Query for FK-from + + select table_name, column_name, referenced_table_name, referenced_column_name + from key_column_usage + where referenced_table_name is not null and table_name = 'user' + order by table_name; + + + + + A. Drop FK from following tables + + 1. ExternalResource + 2. project_type_settings + 3. project_type_project_modules + 4. projectPartner + 5. target + 6. checklist_template_ProjectType + + 7. grading_report_template + 8. milestone_activity_template_ProjectType + 9. ApplicationPeriodProjectType + + 10. user_profile_ProjectType + + 11. idea + 12. project + + B. Fix table ProjectType + + C. Recreate FK for following tables without fixing the table. + 1. idea + 2. project + + */ \ No newline at end of file -- 2.39.5 From c4bf45e022405fba569cc0e6bcd5c69be7d8bfbc Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 20 Jun 2024 12:53:56 +0200 Subject: [PATCH 19/99] task/3382: Fix user_role and user_language and entity class User. --- .../java/se/su/dsv/scipro/system/User.java | 2 +- .../V388__harmonize_table_attribute_name.sql | 93 ++++++++++--------- 2 files changed, 48 insertions(+), 47 deletions(-) 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..07b188550c 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 @@ -64,7 +64,7 @@ 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); diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index badcca6b21..160a417c1a 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -424,10 +424,8 @@ alter table `general_system_settings_system_module` add primary key (general_sys 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; + foreign key (general_system_settings_id) references general_system_settings(id) + on delete cascade on update cascade; -- table: general_system_settings_supervisor_change_recipient @@ -442,10 +440,8 @@ alter table `general_system_settings_supervisor_change_recipient` add primary ke 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; + foreign key (general_system_settings_id) references general_system_settings(id) + on delete cascade on update cascade; -- table: general_system_settings_alarm_recipient @@ -460,10 +456,8 @@ alter table `general_system_settings_alarm_recipient` add primary key (general_s 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; + foreign key (general_system_settings_id) references general_system_settings(id) + on delete cascade on update cascade; -- table: general_system_settings @@ -514,17 +508,13 @@ 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; + 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; + foreign key (user_id) references user(id) + on delete cascade on update cascade; -- table note @@ -533,10 +523,8 @@ 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; + foreign key (user_id) references user(id) + on delete cascade on update cascade; -- table comment & comment_thread @@ -558,17 +546,13 @@ alter table comment rename column `creator_id` to `user_id`; alter table `comment` add constraint fk_comment_user_id - foreign key (user_id) - references user(id) - on delete cascade - on update cascade; + foreign key (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; + foreign key (comment_thread_id) references comment_thread(id) + on delete cascade on update cascade; -- table: reviewer_target @@ -581,10 +565,8 @@ alter table `reviewer_target` add constraint uk_reviewer_target_user_id_year uni alter table `reviewer_target` add constraint fk_reviewer_target_user_id - foreign key (user_id) - references user(id) - on delete cascade - on update cascade; + foreign key (user_id) references user(id) + on delete cascade on update cascade; -- table: notification_delivery_configuration @@ -596,10 +578,8 @@ alter table `notification_delivery_configuration` add constraint uk_one_setting_ 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; + foreign key (user_id) references user(id) + on delete cascade on update cascade; -- table: username @@ -615,10 +595,32 @@ alter table `user_name` add constraint uk_user_name unique(user_name); alter table `user_name` add constraint fk_user_name_user_id - foreign key (user_id) - references user(id) - on delete cascade - on update cascade; + 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_language + +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; + + + /* the mess with ProjectType @@ -644,8 +646,6 @@ alter table `user_name` order by table_name; - - A. Drop FK from following tables 1. ExternalResource @@ -670,4 +670,5 @@ alter table `user_name` 1. idea 2. project + D. other tables can be fixed directly. */ \ No newline at end of file -- 2.39.5 From 3b85bfb6b8835421ac3767e4b34507efd1000d72 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 20 Jun 2024 14:50:24 +0200 Subject: [PATCH 20/99] task/3382: Fix table user, unit and password, and their entity classes. --- .../se/su/dsv/scipro/system/Password.java | 11 +++- .../java/se/su/dsv/scipro/system/Unit.java | 14 +++-- .../java/se/su/dsv/scipro/system/User.java | 42 ++++++++++--- .../V388__harmonize_table_attribute_name.sql | 61 +++++++++++++++++++ 4 files changed, 113 insertions(+), 15 deletions(-) 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/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 07b188550c..f1e5b451f4 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; @@ -76,8 +100,8 @@ public class User extends LazyDeletableDomainObject { @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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 160a417c1a..c44e5113bd 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -619,9 +619,70 @@ alter table `user_language` 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); + +-- fix 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; + +-- fix 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; + +/* *********************************************************************************************** */ /* the mess with ProjectType -- 2.39.5 From b3b4e0dd100357410d929b5de52929b8f53054c2 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 3 Jul 2024 10:33:32 +0200 Subject: [PATCH 21/99] task/3382: Fix table user_profile and it's entity class. --- .../settings/dataobjects/UserProfile.java | 58 ++++++++++++------- .../V388__harmonize_table_attribute_name.sql | 22 +++++++ 2 files changed, 58 insertions(+), 22 deletions(-) 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 8cf7d44e31..1222ef278f 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,25 @@ 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.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 +27,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,18 +38,25 @@ 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) private Collection defaultProjectStatusFilter = EnumSet.of(ProjectStatus.ACTIVE); @@ -44,20 +65,13 @@ public class UserProfile extends DomainObject { @Enumerated(EnumType.STRING) private Collection defaultProjectTeamMemberRolesFilter = EnumSet.of(ProjectTeamMemberRoles.CO_SUPERVISOR); - @Basic(optional = false) - private boolean defaultSupervisorFilter = true; - @ManyToMany @JoinTable( - name = "user_profile_ProjectType", + name = "user_profile_project_type", joinColumns = {@JoinColumn(name = "user_profile_id")} ) private Collection defaultProjectTypeFilter = new ArrayList<>(); - @Basic - @Enumerated(EnumType.STRING) - private Roles selectedRole; - @Override public Long getId() { return this.id; diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index c44e5113bd..3e824fc57a 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -682,6 +682,28 @@ alter table `user` foreign key (password_id) references password(id) on delete cascade on update cascade; +-- fix 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; + /* *********************************************************************************************** */ /* the mess with ProjectType -- 2.39.5 From 2b0b0d7b7174891b92b26510fb60a27d23fe0aac Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 3 Jul 2024 12:54:38 +0200 Subject: [PATCH 22/99] task/3382: Fix table user_profile_default_project_team_member_roles_filter and containing entity class UserProfile. --- .../settings/dataobjects/UserProfile.java | 7 +++++ .../V388__harmonize_table_attribute_name.sql | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) 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 1222ef278f..f027a2e3bf 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 @@ -6,6 +6,7 @@ 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; @@ -59,10 +60,16 @@ public class UserProfile extends DomainObject { @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); @ManyToMany diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 3e824fc57a..1facbc2bca 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -704,6 +704,36 @@ alter table `user_profile` foreign key (user_id) references user(id) on delete cascade on update cascade; +-- fix 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; + +-- fix 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; + /* *********************************************************************************************** */ /* the mess with ProjectType -- 2.39.5 From 7869f17ba333e10a8c10fcde4ce0f8904a10c60f Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 3 Jul 2024 13:22:41 +0200 Subject: [PATCH 23/99] task/3382: Fix table user_profile_project_type and it's containing entity class UserProfile (no fix on project_type yet). --- .../se/su/dsv/scipro/settings/dataobjects/UserProfile.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 f027a2e3bf..fda46e94d0 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 @@ -73,10 +73,8 @@ public class UserProfile extends DomainObject { private Collection defaultProjectTeamMemberRolesFilter = EnumSet.of(ProjectTeamMemberRoles.CO_SUPERVISOR); @ManyToMany - @JoinTable( - name = "user_profile_project_type", - joinColumns = {@JoinColumn(name = "user_profile_id")} - ) + @JoinTable(name = "user_profile_project_type", + joinColumns = @JoinColumn(name = "user_profile_id", referencedColumnName = "id")) private Collection defaultProjectTypeFilter = new ArrayList<>(); @Override -- 2.39.5 From cdaa57aefa814b58862d74a738d1b9f91e6e1419 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 3 Jul 2024 13:23:11 +0200 Subject: [PATCH 24/99] task/3382: Fix table user_profile_project_type and it's containing entity class UserProfile (no fix on project_type yet) - missed db-script. --- .../V388__harmonize_table_attribute_name.sql | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 1facbc2bca..0bdd53e354 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -735,6 +735,32 @@ alter table `user_profile_default_project_team_member_roles_filter` on delete cascade on update cascade; /* *********************************************************************************************** */ +/* Table ProjectType and all tables which reference to ProjectType... */ + +-- fix table user_profile_ProjectType except foreign key to 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`; + +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; + + +-- activate following later +/* +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; +*/ + /* the mess with ProjectType -- 2.39.5 From 27ec8856646d3e4da2ced8369c9196ce4af43662 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 3 Jul 2024 13:44:13 +0200 Subject: [PATCH 25/99] task/3382: Fix table external_resource and the entity class, except fk to project_type. --- .../se/su/dsv/scipro/system/ExternalResource.java | 12 +++++++++++- .../V388__harmonize_table_attribute_name.sql | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 0bdd53e354..66dfd5f394 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -752,9 +752,24 @@ alter table `user_profile_project_type` foreign key (user_profile_id) references user_profile(id) on delete cascade on update cascade; +-- fix table external_resource except foreign key to table project_type + +alter table `ExternalResource` drop foreign key `ExternalResource_ProjectType_relevantFor`; + +rename table `ExternalResource` to `external_resource`; + +alter table `external_resource` rename column `relevantFor_id` to `project_type_id`; + -- activate following later /* +-- add 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 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) -- 2.39.5 From 4de8a02e578783169278b7f5f65b41342408d37e Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 3 Jul 2024 14:55:28 +0200 Subject: [PATCH 26/99] task/3382: Fix table project_type_project_module and JPA-mapping in ProjectType class. --- .../GeneralSystemSettings.java | 2 +- .../se/su/dsv/scipro/system/ProjectType.java | 4 +++- .../V388__harmonize_table_attribute_name.sql | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) 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 21fe2fb803..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 @@ -67,9 +67,9 @@ public class GeneralSystemSettings extends DomainObject { @ElementCollection @Enumerated(EnumType.STRING) - @Column(name = "system_module") @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); @Column(name = "match_responsible_mail", nullable = true) 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..cdbd9e17fd 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 @@ -34,7 +34,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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 66dfd5f394..9e2c1ed492 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -760,9 +760,28 @@ rename table `ExternalResource` to `external_resource`; alter table `external_resource` rename column `relevantFor_id` to `project_type_id`; +-- fix table project_type_project_modules except foreign key to table project_type + +alter table `project_type_project_modules` drop primary key; +alter table `project_type_project_modules` drop foreign key `FK_4attsf1e22qpveesgl6o9b7lg`; + +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 constraint pk_project_type_project_module + primary key(project_type_id, project_module); -- activate following later /* +-- add 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 foreign key reference from external_resource to project_type alter table `external_resource` add constraint fk_external_resource_project_type_id -- 2.39.5 From 94cad840e85d82e2f40604c23850f6548a51a26c Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 3 Jul 2024 15:47:47 +0200 Subject: [PATCH 27/99] task/3382: Fix table project_type_settings and entity class ProjectTypeSettings. --- .../service/MilestoneActivator.java | 2 +- .../scipro/system/ProjectTypeSettings.java | 97 +++++++++++-------- .../V388__harmonize_table_attribute_name.sql | 28 ++++++ .../service/MilestoneActivatorTest.java | 2 +- .../admin/panels/AdminProjectTypePanel.java | 8 +- .../ProjectActiveParticipationListPanel.java | 2 +- .../grading/AbstractExaminationsPanel.java | 4 +- .../IndividualAuthorAssessmentPanel.java | 2 +- 8 files changed, 94 insertions(+), 51 deletions(-) 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/system/ProjectTypeSettings.java b/core/src/main/java/se/su/dsv/scipro/system/ProjectTypeSettings.java index f83d626f1b..7218c073e6 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,83 @@ package se.su.dsv.scipro.system; -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.OneToOne; +import jakarta.persistence.Table; + @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) + @Column(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 +167,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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 9e2c1ed492..d60e92d77e 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -774,8 +774,36 @@ alter table `project_type_project_module` add constraint pk_project_type_project_module primary key(project_type_id, project_module); +-- fix table project_type_settings except foreign key to table project_type + +alter table `project_type_settings` drop foreign key `FK_oxqyb1t8jo7cq2fx8j9slvloa`; +alter table `project_type_settings` drop foreign key `FK_project_class_settings_projectType`; +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_oppositions_to_be_graded`; + +alter table `project_type_settings` add constraint uk_project_type_settings_project_type_id unique(project_type_id); + + -- activate following later /* +-- add 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 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 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/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(); -- 2.39.5 From fe0bed901e0fc2b61ac843f26ccf740fdeee6a4a Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 3 Jul 2024 16:05:22 +0200 Subject: [PATCH 28/99] task/3382: Fix table grading_report_template and entity class GradingReportTemplate. --- .../scipro/report/GradingReportTemplate.java | 23 ++++++++++++++----- .../V388__harmonize_table_attribute_name.sql | 18 ++++++++++++++- 2 files changed, 34 insertions(+), 7 deletions(-) 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 0598728f2c..c9b395d30f 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,17 +1,27 @@ package se.su.dsv.scipro.report; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; + +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.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + 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.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; - @Entity @Table(name = "grading_report_template") public class GradingReportTemplate extends DomainObject { @@ -21,6 +31,7 @@ public class GradingReportTemplate extends DomainObject { private Long id; @OneToOne(optional = false) + @Column(name = "proejct_type_id") private ProjectType projectType; @OneToMany(mappedBy = "gradingReportTemplate", cascade = {CascadeType.ALL}) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index d60e92d77e..de61d7b56e 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -791,13 +791,29 @@ alter table `project_type_settings` rename column `maxOpponentsOnFinalSeminar` t 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_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); +-- fix table grading_report_template except foreign key to 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` rename column `projectType_id` to `project_type_id`; -- activate following later /* + +-- fix table ProjectType + + +-- add 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 foreign key reference from project_type_settings to project_type alter table `project_type_settings` add constraint fk_project_type_settings_project_type_id -- 2.39.5 From e3d843cce251f705e9303c00e6e98613b281abed Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 4 Jul 2024 10:37:09 +0200 Subject: [PATCH 29/99] task/3382: Primarily fixed table grading_criterion_template and grading_criterion_point_template Since JPA MappedSuperclass is used, additional tables like GradingCriterionPoint, criterion, GradingCriterion are partially fixed by renaming some of their columns. --- .../dsv/scipro/report/AbstractCriterion.java | 13 ++--- .../report/AbstractGradingCriterion.java | 3 +- .../report/AbstractGradingCriterionPoint.java | 15 +++-- .../report/GradingCriterionPointTemplate.java | 3 + .../report/GradingCriterionTemplate.java | 13 ++++- .../V388__harmonize_table_attribute_name.sql | 58 +++++++++++++++++-- 6 files changed, 87 insertions(+), 18 deletions(-) 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..68d6b1b276 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,11 @@ 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; @@ -19,13 +18,13 @@ public abstract class AbstractCriterion extends DomainObject { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Basic(optional = false) + @Column(name = "title_sv", nullable = false) private String title; - @Basic(optional = false) + @Column(name = "title_en", nullable = false) private String titleEn; - @Basic(optional = false) + @Column(name = "sort_order", nullable = false) private Integer sortOrder; protected AbstractCriterion() { 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 cda224a3b7..29bcfc0360 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 @@ -1,12 +1,13 @@ package se.su.dsv.scipro.report; import jakarta.persistence.Basic; +import jakarta.persistence.Column; import jakarta.persistence.MappedSuperclass; @MappedSuperclass public abstract class AbstractGradingCriterion extends AbstractCriterion { - @Basic(optional = false) + @Column(name = "points_required_to_pass", nullable = false) protected int pointsRequiredToPass; @Basic 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..5bcca1b670 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,12 +1,17 @@ package se.su.dsv.scipro.report; +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 jakarta.persistence.*; import se.su.dsv.scipro.system.Language; -import java.util.Objects; - @MappedSuperclass public abstract class AbstractGradingCriterionPoint extends DomainObject implements Comparable { public static final int DESCRIPTION_LENGTH = 600; @@ -18,11 +23,11 @@ public abstract class AbstractGradingCriterionPoint extends DomainObject impleme 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; public AbstractGradingCriterionPoint() { 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..93a6e047c6 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") 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index de61d7b56e..a8e02cb1bf 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -802,8 +802,58 @@ alter table `grading_report_template` drop key `FK_qovbb9ql33oaxprfr01w7ss9u`; alter table `grading_report_template` rename column `projectType_id` to `project_type_id`; --- activate following later -/* +-- fix table GradingCriterionPoint (partially, only rename two columns since this table and grading_criterion_pint_template +-- shares same MappedSuperclass AbstractGradingCriterionPoint. JPA-mapping is defined at AbstractGradingCriterionPoint + +alter table `GradingCriterionPoint` rename column `description` to `description_sv`; +alter table `GradingCriterionPoint` rename column `descriptionEn` to `description_en`; + +-- fix table grading_criterion_point_template + +alter table `grading_criterion_point_template` drop foreign 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; + +-- fix table criterion (partially, only rename three columns, since this table criterion shares same +-- JPA MappedSuperclass AbstractCriterion + +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`; + +-- fix table GradingCriterion (partially, only rename four columns, since this table GradingCriterion shares same +-- JPA MappedSuperclass AbstractCriterion and AbstractGradingCriterion. + +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`; + +-- fix 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; + + +/* Activate following later -- fix table ProjectType @@ -812,13 +862,13 @@ alter table `grading_report_template` rename column `projectType_id` to `project 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; + on delete cascade on update cascade; -- add 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; + on delete cascade on update cascade; -- add foreign key reference from project_type_project_module to project_type alter table `project_type_project_module` -- 2.39.5 From 3b1281f4c4fe4ace9d460d62be387a6525cd1eec Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 4 Jul 2024 12:37:08 +0200 Subject: [PATCH 30/99] task/3382: Fix table checklist_template_projectType and related entity class. --- .../scipro/checklist/ChecklistTemplate.java | 5 +- .../V388__harmonize_table_attribute_name.sql | 146 ++++++++++++------ 2 files changed, 101 insertions(+), 50 deletions(-) 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..415e26b074 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 @@ -40,12 +40,13 @@ public class ChecklistTemplate extends DomainObject { 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index a8e02cb1bf..bdaed433c1 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -411,9 +411,9 @@ rename table `FinalSeminarSettings` to `final_seminar_settings`; -- table: general_system_settings_system_module -alter table `general_system_settings_system_modules` drop primary key; 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`; @@ -493,7 +493,7 @@ alter table `general_system_settings` rename column `activeProjectIdeaSupportMai * foreign key references end at table user. */ --- table Program and user_program +-- 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`; @@ -516,7 +516,7 @@ alter table `user_program` foreign key (user_id) references user(id) on delete cascade on update cascade; --- table note +-- table: note alter table `note` drop foreign key `note_ibfk_1`; alter table `note` drop key `user_id`; @@ -526,7 +526,7 @@ alter table `note` foreign key (user_id) references user(id) on delete cascade on update cascade; --- table comment & comment_thread +-- table: comment and comment_thread alter table `comment` drop foreign key `FK38A5EE5FE44F4DBE`; alter table `comment` drop foreign key `FK38A5EE5F45F802F5`; @@ -598,7 +598,7 @@ alter table `user_name` foreign key (user_id) references user(id) on delete cascade on update cascade; --- table user_role +-- table: user_role alter table `user_role` drop foreign key `user_role_user_id`; @@ -607,7 +607,7 @@ alter table `user_role` foreign key (user_id) references user(id) on delete cascade on update cascade; --- table user_language +-- table: user_languages alter table `user_languages` drop foreign key `user_languages_user_id`; alter table `user_languages` drop key `user_languages_user_id`; @@ -619,7 +619,9 @@ alter table `user_language` foreign key (user_id) references user(id) on delete cascade on update cascade; --- table: user, unit and password +/* + * table: user, unit and Password + */ alter table `user` drop foreign key `FK_hpmviec1b7vdg23xtxsalwxw8`; alter table `user` drop key `FK_hpmviec1b7vdg23xtxsalwxw8`; @@ -641,7 +643,7 @@ 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); --- fix table unit +-- table: unit alter table `unit` drop key `identifier`; @@ -656,7 +658,7 @@ alter table `user` foreign key (unit_id) references unit(id) on delete cascade on update cascade; --- fix table password +-- table: Password alter table `Password` drop foreign key `FK_43erxladp39q03wrco68hi9iq`; alter table `Password` drop key `FK_43erxladp39q03wrco68hi9iq`; @@ -682,7 +684,7 @@ alter table `user` foreign key (password_id) references password(id) on delete cascade on update cascade; --- fix table user_profile +-- table: user_profile alter table `user_profile` drop foreign key `FK_user_profile_user`; alter table `user_profile` drop key `FK487E2135895349BF`; @@ -704,7 +706,7 @@ alter table `user_profile` foreign key (user_id) references user(id) on delete cascade on update cascade; --- fix table user_profile_default_project_status_filter +-- 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`; @@ -719,7 +721,7 @@ alter table `user_profile_default_project_status_filter` foreign key (user_profile_id) references user_profile(id) on delete cascade on update cascade; --- fix table user_profile_default_project_team_member_roles_filter +-- 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`; @@ -734,14 +736,21 @@ alter table `user_profile_default_project_team_member_roles_filter` foreign key (user_profile_id) references user_profile(id) on delete cascade on update cascade; -/* *********************************************************************************************** */ -/* Table ProjectType and all tables which reference to ProjectType... */ +/* + * 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. + */ --- fix table user_profile_ProjectType except foreign key to table project_type +-- 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`; @@ -752,18 +761,20 @@ alter table `user_profile_project_type` foreign key (user_profile_id) references user_profile(id) on delete cascade on update cascade; --- fix table external_resource except foreign key to table project_type +-- 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`; --- fix table project_type_project_modules except foreign key to table project_type +-- table: project_type_project_modules except foreign key to coming table project_type -alter table `project_type_project_modules` drop primary key; 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`; @@ -774,10 +785,11 @@ alter table `project_type_project_module` add constraint pk_project_type_project_module primary key(project_type_id, project_module); --- fix table project_type_settings except foreign key to table project_type +-- table: project_type_settings except foreign key to coming table project_type alter table `project_type_settings` drop foreign key `FK_oxqyb1t8jo7cq2fx8j9slvloa`; 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`; @@ -795,48 +807,31 @@ alter table `project_type_settings` rename column `minimumActiveParticipationsTo alter table `project_type_settings` add constraint uk_project_type_settings_project_type_id unique(project_type_id); --- fix table grading_report_template except foreign key to table project_type +-- 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` rename column `projectType_id` to `project_type_id`; --- fix table GradingCriterionPoint (partially, only rename two columns since this table and grading_criterion_pint_template --- shares same MappedSuperclass AbstractGradingCriterionPoint. JPA-mapping is defined at AbstractGradingCriterionPoint +/* >>> START: tables grading_criterion_template, GradingCriterion and criterion share same JPA MappedSuperclass, must be handled together. */ -alter table `GradingCriterionPoint` rename column `description` to `description_sv`; -alter table `GradingCriterionPoint` rename column `descriptionEn` to `description_en`; - --- fix table grading_criterion_point_template - -alter table `grading_criterion_point_template` drop foreign 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; - --- fix table criterion (partially, only rename three columns, since this table criterion shares same --- JPA MappedSuperclass AbstractCriterion +-- 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`; --- fix table GradingCriterion (partially, only rename four columns, since this table GradingCriterion shares same --- JPA MappedSuperclass AbstractCriterion and AbstractGradingCriterion. +-- 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`; --- fix table grading_criterion_template +-- table: grading_criterion_template alter table `grading_criterion_template` drop foreign key `FK_b37xw6uyfj98ff2tsn5t8x5q`; alter table `grading_criterion_template` drop key `FK_b37xw6uyfj98ff2tsn5t8x5q`; @@ -849,31 +844,85 @@ alter table `grading_criterion_template` rename column `gradingReportTemplate_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) + foreign key (grading_report_template_id) references grading_report_template(id) + on delete cascade on update cascade; + +/* >>> END: */ + +/* >>> START: tables 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; + + /* Activate following later --- fix table ProjectType +-- ********************************************************************************** +-- TODO: fix table ProjectType, verify no foreign keys are referenced to ProjectTYpe +-- ********************************************************************************** +-- Add back all foreign key references to project_typ + +-- add 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 (fk_ct_pt_project_type_id) references project_type(id) + on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type(id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type(id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type(id) on delete cascade on update cascade; -- add foreign key reference from external_resource to project_type @@ -899,6 +948,7 @@ alter table `user_profile_project_type` where table_schema = 'tozh4728' and referenced_table_name = 'ProjectType'; + SQL query for FK-to count: select referenced_table_name, count(*) as c from key_column_usage where table_schema = 'tozh4728' and -- 2.39.5 From f750dad22c71f43d0efe796ba8be96d7075ebcd2 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 09:35:32 +0200 Subject: [PATCH 31/99] task/3382: Fix table milestone_activity_template_projectType and JPA-mapping metadata in MilesoneActivityTemplate. --- .../MilestoneActivityTemplate.java | 4 ++- .../V388__harmonize_table_attribute_name.sql | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) 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..247293df64 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 @@ -36,7 +36,9 @@ public class MilestoneActivityTemplate extends LazyDeletableDomainObject { @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<>(); diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index bdaed433c1..134def5bc8 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -891,16 +891,40 @@ alter table `checklist_template_project_type` 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 `milestone_activity_template_ProjectType_ibfk_1`; +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; /* Activate following later -- ********************************************************************************** --- TODO: fix table ProjectType, verify no foreign keys are referenced to ProjectTYpe +-- TODO: fix table ProjectType, verify no foreign keys are referenced to ProjectTYpe before fix it -- ********************************************************************************** -- Add back all foreign key references to project_typ +-- add 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 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 -- 2.39.5 From 237d15351e303099f336786eaf2807c2b6615682 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 10:00:36 +0200 Subject: [PATCH 32/99] task/3382: Partially fix table idea Remove foreign key from table idea to table ProjectType, rename the foreign key column at idea. Change JPA-metadata in Idea entity class as well. --- .../main/java/se/su/dsv/scipro/match/Idea.java | 1 + .../V388__harmonize_table_attribute_name.sql | 15 +++++++++++++++ 2 files changed, 16 insertions(+) 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..878d6a166f 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 @@ -23,6 +23,7 @@ public class Idea extends DomainObject { private Long id; @ManyToOne(optional = false) + @JoinColumn(name = "project_type_id") private ProjectType projectType; @Enumerated(EnumType.STRING) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 134def5bc8..c050a76c6c 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -910,6 +910,15 @@ alter table `milestone_activity_template_project_type` 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`; + + /* Activate following later @@ -919,6 +928,12 @@ alter table `milestone_activity_template_project_type` -- Add back all foreign key references to project_typ +-- add 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 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 -- 2.39.5 From fd248c55e3dc41488f1b7663ff9168772be2530c Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 10:10:08 +0200 Subject: [PATCH 33/99] task/3382: Partially fix table project Remove foreign key from table project to table ProjectType, rename the foreign key column at table project. Change JPA-metadata in Project entity class as well. --- .../java/se/su/dsv/scipro/project/Project.java | 1 + .../V388__harmonize_table_attribute_name.sql | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) 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 92c82a9014..639dac814e 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 @@ -67,6 +67,7 @@ public class Project extends DomainObject { private String stateOfMindReason; @ManyToOne(optional = false) + @JoinColumn(name = "project_type_id") private ProjectType projectType; @Embedded diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index c050a76c6c..6d260fb9a7 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -917,6 +917,16 @@ 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`; +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`; + @@ -928,6 +938,12 @@ alter table `idea` rename column `projectType_id` to `project_type_id`; -- Add back all foreign key references to project_typ +-- add 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 foreign key reference from idea to project_type alter table `idea` add constraint fk_idea_project_type_id -- 2.39.5 From ae86b54692d78ed877c10f979f973032489fe79d Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 11:59:24 +0200 Subject: [PATCH 34/99] task/3382: fix table target fixed table target, without foreign key references to coming table application_period and project_type, fixed entity class as well. --- .../java/se/su/dsv/scipro/match/Target.java | 4 +- .../V388__harmonize_table_attribute_name.sql | 87 ++++++++++++++++--- 2 files changed, 79 insertions(+), 12 deletions(-) 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 6d260fb9a7..5f95484ca0 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -745,7 +745,7 @@ alter table `user_profile_default_project_team_member_roles_filter` * 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 +-- 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`; @@ -761,7 +761,7 @@ alter table `user_profile_project_type` 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 +-- 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`; @@ -770,7 +770,7 @@ 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 +-- 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`; @@ -785,7 +785,7 @@ alter table `project_type_project_module` add constraint pk_project_type_project_module primary key(project_type_id, project_module); --- table: project_type_settings except foreign key to coming table project_type +-- table: project_type_settings, except foreign key to coming table project_type alter table `project_type_settings` drop foreign key `FK_oxqyb1t8jo7cq2fx8j9slvloa`; alter table `project_type_settings` drop foreign key `FK_project_class_settings_projectType`; @@ -807,14 +807,14 @@ alter table `project_type_settings` rename column `minimumActiveParticipationsTo 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 +-- 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` rename column `projectType_id` to `project_type_id`; -/* >>> START: tables grading_criterion_template, GradingCriterion and criterion share same JPA MappedSuperclass, must be handled together. */ +/* >>> 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 @@ -849,7 +849,7 @@ alter table `grading_criterion_template` /* >>> END: */ -/* >>> START: tables grading_criterion_point_template and GradingCriterionPoint share same JPA MappedSuperclass, must be handled together. */ +/* >>> 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. @@ -873,7 +873,7 @@ alter table `grading_criterion_point_template` /* >>> END: */ --- table: checklist_template_ProjectType except foreign key to coming table project_type +-- 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`; @@ -891,7 +891,7 @@ alter table `checklist_template_project_type` 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 +-- table: milestone_activity_template_ProjectType, except foreign key to coming table project_type alter table `milestone_activity_template_ProjectType` drop foreign key `milestone_activity_template_ProjectType_ibfk_1`; alter table `milestone_activity_template_ProjectType` drop foreign key `FKFB3FC75157F6B071`; @@ -927,16 +927,83 @@ alter table `project` drop key `FKED904B19B2B6081F`; alter table `project` rename column `projectType_id` to `project_type_id`; +/* >>> STACK PUSH (1st table group: target, projectPartner, ApplicationPeriodProjectType): + * 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. + * 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 and applicationperiodexcemption + * + * Foreign keys will be then added in reverse order, it's like a stack pop. + */ + +-- 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; + + + + + + + + + /* Activate following later +-- ********************************************************************************** +-- TODO: fix table ApplicationPeriod, verify no foreign keys are referenced to ApplicationPeriod before fix it +-- ********************************************************************************** + + +-- ********************************************************************************** +-- TODO: Add back all foreign key references to application_period +-- ********************************************************************************** + +-- add 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; + -- ********************************************************************************** -- TODO: fix table ProjectType, verify no foreign keys are referenced to ProjectTYpe before fix it -- ********************************************************************************** --- Add back all foreign key references to project_typ + +-- ********************************************************************************** +-- TODO: Add back all foreign key references to project_type +-- ********************************************************************************** + +-- add 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; -- add foreign key reference from project to project_type alter table `project` -- 2.39.5 From 340c72dd3871a3e3d1f7e37d9247e516c91306be Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 12:16:41 +0200 Subject: [PATCH 35/99] task/3382: Fix table project_partner Fix table project_partner, except foreign key references to comming table application_period and project_type. Fixed its entity class as well. --- .../scipro/projectpartner/ProjectPartner.java | 23 ++++++++++--- .../V388__harmonize_table_attribute_name.sql | 33 ++++++++++++++++++- 2 files changed, 50 insertions(+), 6 deletions(-) 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..b182664bc5 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,9 +31,11 @@ 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 @@ -30,7 +43,7 @@ public class ProjectPartner extends DomainObject { 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 5f95484ca0..19d56f351c 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -927,7 +927,7 @@ alter table `project` drop key `FKED904B19B2B6081F`; alter table `project` rename column `projectType_id` to `project_type_id`; -/* >>> STACK PUSH (1st table group: target, projectPartner, ApplicationPeriodProjectType): +/* >>> STACK PUSH * 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. @@ -943,6 +943,8 @@ alter table `project` rename column `projectType_id` to `project_type_id`; * Foreign keys will be then added in reverse order, it's like a stack pop. */ +-- 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`; @@ -962,8 +964,25 @@ alter table `target` 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; @@ -984,6 +1003,12 @@ alter table `target` -- TODO: Add back all foreign key references to application_period -- ********************************************************************************** +-- add 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 foreign key reference from target to application_period alter table `target` add constraint fk_target_application_period_id @@ -999,6 +1024,12 @@ alter table `target` -- TODO: Add back all foreign key references to project_type -- ********************************************************************************** +-- add foreign key reference from target 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 foreign key reference from target to project_type alter table `target` add constraint fk_target_project_type_id -- 2.39.5 From 770d0aff3106392e350749ff0ea749990d581032 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 12:52:12 +0200 Subject: [PATCH 36/99] task/3382: Fix table ApplicationPeriodProjectType Fixed table ApplicationPeriodProjectType except any foreign key references, fixed its entity class as well. --- .../match/ApplicationPeriodProjectType.java | 6 + .../V388__harmonize_table_attribute_name.sql | 164 +++++++++++------- 2 files changed, 109 insertions(+), 61 deletions(-) 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 19d56f351c..8d6b081e89 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -424,7 +424,7 @@ alter table `general_system_settings_system_module` add primary key (general_sys 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) + foreign key (general_system_settings_id) references general_system_settings (id) on delete cascade on update cascade; -- table: general_system_settings_supervisor_change_recipient @@ -440,7 +440,7 @@ alter table `general_system_settings_supervisor_change_recipient` add primary ke 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) + foreign key (general_system_settings_id) references general_system_settings (id) on delete cascade on update cascade; -- table: general_system_settings_alarm_recipient @@ -456,7 +456,7 @@ alter table `general_system_settings_alarm_recipient` add primary key (general_s 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) + foreign key (general_system_settings_id) references general_system_settings (id) on delete cascade on update cascade; -- table: general_system_settings @@ -508,12 +508,12 @@ 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) + 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) + foreign key (user_id) references user (id) on delete cascade on update cascade; -- table: note @@ -523,7 +523,7 @@ alter table `note` drop key `user_id`; alter table `note` add constraint fk_note_user_id - foreign key (user_id) references user(id) + foreign key (user_id) references user (id) on delete cascade on update cascade; -- table: comment and comment_thread @@ -546,12 +546,12 @@ alter table comment rename column `creator_id` to `user_id`; alter table `comment` add constraint fk_comment_user_id - foreign key (user_id) references user(id) + foreign key (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) + foreign key (comment_thread_id) references comment_thread (id) on delete cascade on update cascade; -- table: reviewer_target @@ -565,7 +565,7 @@ alter table `reviewer_target` add constraint uk_reviewer_target_user_id_year uni alter table `reviewer_target` add constraint fk_reviewer_target_user_id - foreign key (user_id) references user(id) + foreign key (user_id) references user (id) on delete cascade on update cascade; -- table: notification_delivery_configuration @@ -578,7 +578,7 @@ alter table `notification_delivery_configuration` add constraint uk_one_setting_ alter table `notification_delivery_configuration` add constraint fk_notification_delivery_configuration_user_id - foreign key (user_id) references user(id) + foreign key (user_id) references user (id) on delete cascade on update cascade; -- table: username @@ -595,7 +595,7 @@ alter table `user_name` add constraint uk_user_name unique(user_name); alter table `user_name` add constraint fk_user_name_user_id - foreign key (user_id) references user(id) + foreign key (user_id) references user (id) on delete cascade on update cascade; -- table: user_role @@ -604,7 +604,7 @@ 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) + foreign key (user_id) references user (id) on delete cascade on update cascade; -- table: user_languages @@ -616,7 +616,7 @@ 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) + foreign key (user_id) references user (id) on delete cascade on update cascade; /* @@ -655,7 +655,7 @@ alter table `unit` add constraint uk_unit_identifier unique(identifier); alter table `user` add constraint fk_user_unit_id - foreign key (unit_id) references unit(id) + foreign key (unit_id) references unit (id) on delete cascade on update cascade; -- table: Password @@ -674,14 +674,14 @@ create index idx_password_deleted on password(deleted); alter table `password` add constraint fk_password_user_id - foreign key (user_id) references 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) + foreign key (password_id) references password (id) on delete cascade on update cascade; -- table: user_profile @@ -703,7 +703,7 @@ 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) + foreign key (user_id) references user (id) on delete cascade on update cascade; -- table: user_profile_default_project_status_filter @@ -718,7 +718,7 @@ alter table `user_profile_default_project_status_filter` rename column `defaultP 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) + foreign key (user_profile_id) references user_profile (id) on delete cascade on update cascade; -- table: user_profile_default_project_team_member_roles_filter @@ -733,7 +733,7 @@ alter table `user_profile_default_project_team_member_roles_filter` rename colum 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) + foreign key (user_profile_id) references user_profile (id) on delete cascade on update cascade; /* @@ -758,7 +758,7 @@ alter table `user_profile_project_type` rename column `defaultProjectTypeFilter_ 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) + 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 @@ -844,7 +844,7 @@ alter table `grading_criterion_template` rename column `gradingReportTemplate_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) + foreign key (grading_report_template_id) references grading_report_template (id) on delete cascade on update cascade; /* >>> END: */ @@ -868,7 +868,7 @@ alter table `grading_criterion_point_template` rename column `gradingCriterionTe 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) + foreign key (grading_criterion_template_id) references grading_criterion_template (id) on delete cascade on update cascade; /* >>> END: */ @@ -888,7 +888,7 @@ alter table `checklist_template_project_type` add primary key (checklist_templat alter table `checklist_template_project_type` add constraint fk_ct_pt_checklist_template_id - foreign key (checklist_template_id) references 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 @@ -907,7 +907,7 @@ alter table `milestone_activity_template_project_type` add primary key (`milesto 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) + 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. @@ -927,23 +927,25 @@ alter table `project` drop key `FKED904B19B2B6081F`; alter table `project` rename column `projectType_id` to `project_type_id`; -/* >>> STACK PUSH - * 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. - * Removal of foreign keys and renaming of columns and table name must be fixed in following order: +/* + * 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. * - * 1. target, projectPartner, ApplicationPeriodProjectType - * 2. ActivityTemplate and ActivityPlanTemplate - * 3. ApplicationPeriod and applicationperiodexcemption + * 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. * - * Foreign keys will be then added in reverse order, it's like a stack pop. + * 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 and applicationperiodexcemption + * + * Foreign keys will be then added in reverse order, it's like a stack pop. */ --- 1st table group: target, projectPartner, ApplicationPeriodProjectType +-- >>> STACK PUSH: 1st table group: target, projectPartner, ApplicationPeriodProjectType -- table: target, except foreign key to coming table project_type, and application_period @@ -961,7 +963,7 @@ alter table `target` add primary key (application_period_id, project_type_id, us alter table `target` add constraint fk_target_user_id - foreign key (user_id) references 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 @@ -981,19 +983,47 @@ alter table `project_partner` rename column `applicationPeriod_id` to `applicati alter table `project_partner` add constraint fk_project_partner_user_id - foreign key (user_id) references 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); /* Activate following later +-- ********************************************************************************** +-- TODO: fix table ActivityPlanTemplate, verify no foreign keys are referenced to ActivityPlanTemplate before fix it +-- ********************************************************************************** + +-- ********************************************************************************** +-- TODO: Add back all foreign key references to activity_plan_template +-- ********************************************************************************** + +-- 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; + + + -- ********************************************************************************** -- TODO: fix table ApplicationPeriod, verify no foreign keys are referenced to ApplicationPeriod before fix it -- ********************************************************************************** @@ -1003,16 +1033,22 @@ alter table `project_partner` -- TODO: Add back all foreign key references to application_period -- ********************************************************************************** +-- add 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 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) + foreign key (application_period_id) references application_period (id) on delete cascade on update cascade; -- add 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) + foreign key (application_period_id) references application_period (id) on delete cascade on update cascade; -- ********************************************************************************** @@ -1024,95 +1060,101 @@ alter table `target` -- TODO: Add back all foreign key references to project_type -- ********************************************************************************** +-- add foreign key reference from target 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 foreign key reference from target to project_type alter table `project_partner` add constraint fk_project_partner_project_type_id - foreign key (project_type_id) references project_type(id) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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 (fk_ct_pt_project_type_id) references project_type(id) + foreign key (fk_ct_pt_project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; -- add 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) + foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; */ /* the mess with ProjectType - SQL query for FK-to: +>>> SQL query for FK-to: select table_name, column_name, referenced_table_name, referenced_column_name - from key_column_usage + from information_schema.key_column_usage where table_schema = 'tozh4728' and referenced_table_name = 'ProjectType'; - SQL query for FK-to count: +>>> SQL query for FK-to count: select referenced_table_name, count(*) as c - from key_column_usage + from information_schema.key_column_usage where table_schema = 'tozh4728' and referenced_table_name is not null group by referenced_table_name order by c desc; - SQL Query for FK-from +>>> SQL Query for FK-from - select table_name, column_name, referenced_table_name, referenced_column_name - from key_column_usage - where referenced_table_name is not null and table_name = 'user' + select table_name, column_name, referenced_table_name, referenced_column_name + from information_schema.key_column_usage + where referenced_table_name is not null and table_name = 'user' order by table_name; -- 2.39.5 From 1fc8daa0a3b1b2672f54e7e369effeca7d5bfd2e Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 14:24:16 +0200 Subject: [PATCH 37/99] task/3382: Fix table ActivityTemplate Fixed table ActivityTemplate, except foreign key to coming table activity_plan_template. Fixed its entity class as well. --- .../scipro/activityplan/ActivityTemplate.java | 24 +++++++-- .../V388__harmonize_table_attribute_name.sql | 50 ++++++++++++++++--- 2 files changed, 61 insertions(+), 13 deletions(-) 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..2b24253c8b 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,12 +1,24 @@ package se.su.dsv.scipro.activityplan; +import java.util.Objects; + +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 @@ -20,18 +32,20 @@ public class ActivityTemplate extends DomainObject { private String description; @ManyToOne + @JoinColumn(name = "activity_plan_template_id") private ActivityPlanTemplate activityPlanTemplate; - @Column(nullable = false) + @Column(name = "days_offset", nullable = false) private int daysOffset; @Enumerated(EnumType.STRING) private Action action = Action.NONE; - @Column(nullable = false) + @Column(name =" number_in_order", nullable = false) private int numberInOrder = Integer.MAX_VALUE; @ManyToOne(optional = true) + @JoinColumn(name = "checklist_template_id") private ChecklistTemplate checklistTemplate; public ActivityTemplate() { diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 8d6b081e89..d40d88d990 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -964,7 +964,7 @@ alter table `target` add primary key (application_period_id, project_type_id, us alter table `target` add constraint fk_target_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- table: projectPartner, except foreign key to coming table project_type, and application_period @@ -984,7 +984,7 @@ alter table `project_partner` rename column `applicationPeriod_id` to `applicati alter table `project_partner` add constraint fk_project_partner_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- table: ApplicationPeriodProjectType, except foreign key to coming table application_period, project_type and activity_plan_template. @@ -1004,17 +1004,46 @@ alter table `application_period_project_type` rename column `activityPlanTemplat alter table `application_period_project_type` add primary key (application_period_id, project_type_id); +-- >>> STACK PUSH: 2nd table group: target, 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 cascade on update cascade; + +-- table: ActivityPlanTemplate (at this stage, no any foreign key is are referenced to ActivityPlanTemplate) + + + /* Activate following later -- ********************************************************************************** --- TODO: fix table ActivityPlanTemplate, verify no foreign keys are referenced to ActivityPlanTemplate before fix it +-- TODO: -- Add back all foreign key references to activity_plan_template -- ********************************************************************************** --- ********************************************************************************** --- TODO: 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` @@ -1030,7 +1059,7 @@ alter table `application_period_project_type` -- ********************************************************************************** --- TODO: Add back all foreign key references to application_period +-- TODO: -- Add back all foreign key references to application_period -- ********************************************************************************** -- add foreign key reference from application_period_project_type to application_period @@ -1057,7 +1086,7 @@ alter table `target` -- ********************************************************************************** --- TODO: Add back all foreign key references to project_type +-- TODO: -- Add back all foreign key references to project_type -- ********************************************************************************** -- add foreign key reference from target to project_type @@ -1157,6 +1186,11 @@ alter table `user_profile_project_type` where referenced_table_name is not null and table_name = 'user' order by table_name; +>>> Show foreign keys + + select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name + from information_schema.key_column_usage + where table_schema = 'tozh4728' and table_name = 'ActivityTemplate'; A. Drop FK from following tables -- 2.39.5 From 83ae6491f83fa81706dc48212cc75c18e1a09e36 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 14:46:57 +0200 Subject: [PATCH 38/99] task/3382: Fix table ActivityPlanTemplate Fix table ActivityPlanTemplate and its entity class. Put back foreign key references from activity_template and application_period_project_type as well. --- .../activityplan/ActivityPlanTemplate.java | 124 ++++++++++-------- .../V388__harmonize_table_attribute_name.sql | 23 +++- 2 files changed, 88 insertions(+), 59 deletions(-) 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..d02768de8c 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,42 +1,87 @@ 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.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 @Cacheable(true) +@Table(name = "activity_plan_template") 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(name = "is_sys_admin_template", nullable=false) + private boolean isSysAdminTemplate = false; @Column(nullable=false) private String title; - + @Lob private String description; - - @Column(nullable=false) - private boolean isSysAdminTemplate = false; + + @OrderColumn(name = "number_in_order") + @OneToMany(mappedBy="activityPlanTemplate", orphanRemoval=true, cascade=CascadeType.ALL) + private List activityTemplates = new ArrayList<>(); + + @ManyToOne(optional=false) + @JoinColumn(name = "user_id") + private User creator; + + + @Override + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + 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 void addActivity(ActivityTemplate activity){ activity.setActivityPlanTemplate(this); @@ -52,47 +97,22 @@ public class ActivityPlanTemplate extends DomainObject { activityTemplates.addAll(activities); } - @Override - public Long getId() { - return this.id; + public List getActivityTemplates(){ + return Collections.unmodifiableList(activityTemplates); + } + + public void setActivityTemplates(List activityTemplates){ + this.activityTemplates = new ArrayList<>(activityTemplates); } 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 void setSysAdminTemplate(boolean isSysAdminTemplate) { - this.isSysAdminTemplate = isSysAdminTemplate; - } - @Override public boolean equals(final Object o) { if (o == this) return true; diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index d40d88d990..aa5d3d0ea9 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -1004,7 +1004,7 @@ alter table `application_period_project_type` rename column `activityPlanTemplat alter table `application_period_project_type` add primary key (application_period_id, project_type_id); --- >>> STACK PUSH: 2nd table group: target, ActivityPlanTemplate and ActivityTemplate +-- >>> STACK PUSH: 2nd table group: ActivityPlanTemplate and ActivityTemplate -- table: ActivityTemplate, except foreign key to coming table activity_plan_template @@ -1028,15 +1028,21 @@ alter table `activity_template` -- table: ActivityPlanTemplate (at this stage, no any foreign key is are 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 `user_id`; +alter table `activity_plan_template` + add constraint fk_activity_plan_template_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; -/* Activate following later - --- ********************************************************************************** --- TODO: -- Add back all foreign key references to activity_plan_template --- ********************************************************************************** +-- 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` @@ -1044,15 +1050,18 @@ alter table `activity_template` 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!!! + +/* Activate following later + -- ********************************************************************************** -- TODO: fix table ApplicationPeriod, verify no foreign keys are referenced to ApplicationPeriod before fix it -- ********************************************************************************** -- 2.39.5 From 1d3ea2e4efa599d9b14e2dd193b12b81ec012810 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 15:27:04 +0200 Subject: [PATCH 39/99] task/3382: Fix table applicationperiodexemption and part of table idea Table applicationperiodexemption is fixed except foreign key to coming table application_period. Its related entity class is fixed as well. Table idea removed foreign key reference to table ApplicationPeriod. --- .../match/ApplicationPeriodExemption.java | 21 ++++- .../V388__harmonize_table_attribute_name.sql | 94 ++++++++++++++----- 2 files changed, 86 insertions(+), 29 deletions(-) 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index aa5d3d0ea9..c81012387e 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -916,7 +916,6 @@ alter table `milestone_activity_template_project_type` 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`; 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. @@ -934,13 +933,14 @@ alter table `project` rename column `projectType_id` to `project_type_id`; * * 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. + * 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 and applicationperiodexcemption + * 3. ApplicationPeriod, applicationperiodexcemption, and idea as well * * Foreign keys will be then added in reverse order, it's like a stack pop. */ @@ -1040,7 +1040,7 @@ alter table `activity_plan_template` rename column `creator_id` to `user_id`; alter table `activity_plan_template` add constraint fk_activity_plan_template_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- Add back all foreign key references to activity_plan_template @@ -1048,42 +1048,88 @@ alter table `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; + 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; + 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, verify no foreign keys are referenced to ApplicationPeriod before fix it + + /* Activate following later --- ********************************************************************************** --- TODO: fix table ApplicationPeriod, verify no foreign keys are referenced to ApplicationPeriod before fix it --- ********************************************************************************** -- ********************************************************************************** -- TODO: -- Add back all foreign key references to application_period -- ********************************************************************************** --- add foreign key reference from application_period_project_type to application_period +-- 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; + +-- 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 foreign key reference from project_partner to application_period +-- 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 foreign key reference from target to application_period +-- 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) @@ -1098,73 +1144,73 @@ alter table `target` -- TODO: -- Add back all foreign key references to project_type -- ********************************************************************************** --- add foreign key reference from target to project_type +-- add back foreign key reference from target 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 foreign key reference from target to project_type +-- add back foreign key reference from target 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 foreign key reference from target to project_type +-- 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; --- add foreign key reference from project to project_type +-- 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 foreign key reference from idea to project_type +-- 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 foreign key reference from milestone_activity_template_project_type to project_type +-- 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 foreign key reference from checklist_template_project_type to project_type +-- 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 (fk_ct_pt_project_type_id) references project_type (id) on delete cascade on update cascade; --- add foreign key reference from grading_report_template to project_type +-- 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 foreign key reference from project_type_settings to project_type +-- 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 foreign key reference from project_type_project_module to project_type +-- 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 foreign key reference from external_resource to project_type +-- 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 foreign key reference from user_profile_project_type to project_type. +-- 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) -- 2.39.5 From fcd0a4c8b60c7601f83990fa7c4b492ec6dcdc9b Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 15:49:31 +0200 Subject: [PATCH 40/99] task/3382: Finally, application_period table is ready. --- .../dsv/scipro/match/ApplicationPeriod.java | 36 ++++-- .../V388__harmonize_table_attribute_name.sql | 103 ++++++++++-------- 2 files changed, 80 insertions(+), 59 deletions(-) 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/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index c81012387e..29f17358ba 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -425,7 +425,7 @@ alter table `general_system_settings_system_module` add primary key (general_sys 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; + on delete cascade on update cascade; -- table: general_system_settings_supervisor_change_recipient @@ -441,7 +441,7 @@ alter table `general_system_settings_supervisor_change_recipient` add primary ke 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; + on delete cascade on update cascade; -- table: general_system_settings_alarm_recipient @@ -457,7 +457,7 @@ alter table `general_system_settings_alarm_recipient` add primary key (general_s 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; + on delete cascade on update cascade; -- table: general_system_settings @@ -509,12 +509,12 @@ 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; + 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; + on delete cascade on update cascade; -- table: note @@ -524,7 +524,7 @@ 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; + on delete cascade on update cascade; -- table: comment and comment_thread @@ -547,12 +547,12 @@ alter table comment rename column `creator_id` to `user_id`; alter table `comment` add constraint fk_comment_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + 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; + on delete cascade on update cascade; -- table: reviewer_target @@ -566,7 +566,7 @@ alter table `reviewer_target` add constraint uk_reviewer_target_user_id_year uni alter table `reviewer_target` add constraint fk_reviewer_target_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- table: notification_delivery_configuration @@ -579,7 +579,7 @@ alter table `notification_delivery_configuration` add constraint uk_one_setting_ 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; + on delete cascade on update cascade; -- table: username @@ -596,7 +596,7 @@ alter table `user_name` add constraint uk_user_name unique(user_name); alter table `user_name` add constraint fk_user_name_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- table: user_role @@ -605,7 +605,7 @@ 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; + on delete cascade on update cascade; -- table: user_languages @@ -617,7 +617,7 @@ 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; + on delete cascade on update cascade; /* * table: user, unit and Password @@ -656,7 +656,7 @@ alter table `unit` add constraint uk_unit_identifier unique(identifier); alter table `user` add constraint fk_user_unit_id foreign key (unit_id) references unit (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- table: Password @@ -675,14 +675,14 @@ 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; + 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; + on delete cascade on update cascade; -- table: user_profile @@ -704,7 +704,7 @@ 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; + on delete cascade on update cascade; -- table: user_profile_default_project_status_filter @@ -719,7 +719,7 @@ alter table `user_profile_default_project_status_filter` rename column `defaultP 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; + on delete cascade on update cascade; -- table: user_profile_default_project_team_member_roles_filter @@ -734,7 +734,7 @@ alter table `user_profile_default_project_team_member_roles_filter` rename colum 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; + on delete cascade on update cascade; /* * Step 6: table ProjectType and related tables. @@ -759,7 +759,7 @@ alter table `user_profile_project_type` rename column `defaultProjectTypeFilter_ 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; + on delete cascade on update cascade; -- table: ExternalResource, except foreign key to coming table project_type @@ -869,7 +869,7 @@ alter table `grading_criterion_point_template` rename column `gradingCriterionTe 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; + on delete cascade on update cascade; /* >>> END: */ @@ -889,7 +889,7 @@ alter table `checklist_template_project_type` add primary key (checklist_templat 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; + on delete cascade on update cascade; -- table: milestone_activity_template_ProjectType, except foreign key to coming table project_type @@ -908,7 +908,7 @@ alter table `milestone_activity_template_project_type` add primary key (`milesto 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; + 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. @@ -964,7 +964,7 @@ alter table `target` add primary key (application_period_id, project_type_id, us alter table `target` add constraint fk_target_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- table: projectPartner, except foreign key to coming table project_type, and application_period @@ -984,7 +984,7 @@ alter table `project_partner` rename column `applicationPeriod_id` to `applicati alter table `project_partner` add constraint fk_project_partner_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- table: ApplicationPeriodProjectType, except foreign key to coming table application_period, project_type and activity_plan_template. @@ -1024,9 +1024,9 @@ alter table `activity_template` rename column `checkListTemplate_id` to `checkli alter table `activity_template` add constraint fk_activity_template_checklist_template_id foreign key (checklist_template_id) references checklist_template (id) - on delete cascade on update cascade; + on delete cascade on update cascade; --- table: ActivityPlanTemplate (at this stage, no any foreign key is are referenced to ActivityPlanTemplate) +-- 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`; @@ -1040,7 +1040,7 @@ alter table `activity_plan_template` rename column `creator_id` to `user_id`; alter table `activity_plan_template` add constraint fk_activity_plan_template_user_id foreign key (user_id) references user (id) - on delete cascade on update cascade; + on delete cascade on update cascade; -- Add back all foreign key references to activity_plan_template @@ -1048,13 +1048,13 @@ alter table `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; + 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; + on delete cascade on update cascade; -- >>> STACK POP: 2nd table group (ActivityPlanTemplate and ActivityTemplate) is done!!! @@ -1098,25 +1098,31 @@ alter table `idea` drop key `FK6E051897BEC322C1`; alter table `idea` rename column `applicationPeriod_id` to `application_period_id`; --- table: ApplicationPeriod, verify no foreign keys are referenced to ApplicationPeriod before fix it +-- 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 -/* Activate following later - - - --- ********************************************************************************** --- TODO: -- Add back all foreign key references to application_period --- ********************************************************************************** +-- 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; - + 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 @@ -1135,11 +1141,14 @@ alter table `target` foreign key (application_period_id) references application_period (id) on delete cascade on update cascade; --- ********************************************************************************** --- TODO: fix table ProjectType, verify no foreign keys are referenced to ProjectTYpe before fix it --- ********************************************************************************** +-- table: ProjectType (finally!! at this stage, no any foreign key is referenced to ProjectType) +-- >>> STACK POP: 1st table group: target, projectPartner, ApplicationPeriodProjectType is done!!! + + +/* Activate following later + -- ********************************************************************************** -- TODO: -- Add back all foreign key references to project_type -- ********************************************************************************** @@ -1190,25 +1199,25 @@ alter table `checklist_template_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; + 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; + 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; + 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; + 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` -- 2.39.5 From 5b09b0963eaa627a45a1679e811a371d44d518db Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 16:05:40 +0200 Subject: [PATCH 41/99] task/3382: ProjectType is finally fixed. --- .../se/su/dsv/scipro/system/ProjectType.java | 21 +++++++++++++++++-- .../V388__harmonize_table_attribute_name.sql | 17 +++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) 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 cdbd9e17fd..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 diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 29f17358ba..3f19b3efcd 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -1143,23 +1143,19 @@ alter table `target` -- table: ProjectType (finally!! at this stage, no any foreign key is referenced to ProjectType) +rename table `ProjectType` to `project_type`; --- >>> STACK POP: 1st table group: target, projectPartner, ApplicationPeriodProjectType is done!!! +alter table `project_type` rename column `degreeType` to `degree_type`; +-- Add back all foreign key references to project_type -/* Activate following later - --- ********************************************************************************** --- TODO: -- Add back all foreign key references to project_type --- ********************************************************************************** - --- add back foreign key reference from target 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 target to project_type +-- 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) @@ -1171,6 +1167,8 @@ alter table `target` 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 @@ -1224,7 +1222,6 @@ 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; -*/ /* the mess with ProjectType -- 2.39.5 From 2e55ae0df68e56689188630430de0c1ea06b8c27 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 5 Jul 2024 16:16:41 +0200 Subject: [PATCH 42/99] task/3382: Improve comments. --- .../V388__harmonize_table_attribute_name.sql | 54 +++++-------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index 3f19b3efcd..ddcaa4fd31 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -1224,58 +1224,32 @@ alter table `user_profile_project_type` on delete cascade on update cascade; -/* the mess with ProjectType +/* Useful SQL >>> SQL query for FK-to: - select table_name, column_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage - where table_schema = 'tozh4728' and - referenced_table_name = 'ProjectType'; +select table_name, column_name, referenced_table_name, referenced_column_name + from information_schema.key_column_usage + where table_schema = 'tozh4728' and referenced_table_name = 'ProjectType'; >>> SQL query for FK-to count: + select referenced_table_name, count(*) as c from information_schema.key_column_usage - where table_schema = 'tozh4728' and - referenced_table_name is not null + where table_schema = 'tozh4728' and referenced_table_name is not null group by referenced_table_name order by c desc; >>> SQL Query for FK-from - select table_name, column_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage - where referenced_table_name is not null and table_name = 'user' - order by table_name; + select table_name, column_name, referenced_table_name, referenced_column_name + from information_schema.key_column_usage + where referenced_table_name is not null and table_name = 'user' +order by table_name; >>> Show foreign keys - select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage - where table_schema = 'tozh4728' and table_name = 'ActivityTemplate'; +select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name + from information_schema.key_column_usage +where table_schema = 'tozh4728' and table_name = 'ActivityTemplate' and constraint_name != 'PRIMARY'; - A. Drop FK from following tables - - 1. ExternalResource - 2. project_type_settings - 3. project_type_project_modules - 4. projectPartner - 5. target - 6. checklist_template_ProjectType - - 7. grading_report_template - 8. milestone_activity_template_ProjectType - 9. ApplicationPeriodProjectType - - 10. user_profile_ProjectType - - 11. idea - 12. project - - B. Fix table ProjectType - - C. Recreate FK for following tables without fixing the table. - 1. idea - 2. project - - D. other tables can be fixed directly. - */ \ No newline at end of file +*/ \ No newline at end of file -- 2.39.5 From 9d9ee49b2c7dab2f50f9552791a5d4972cb90c74 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 10 Jul 2024 13:51:00 +0200 Subject: [PATCH 43/99] task/3382: Fix a few errors Fix a few errors in SQL-script and JPA-mappings. --- .../main/java/se/su/dsv/scipro/match/Idea.java | 1 + .../dsv/scipro/projectpartner/ProjectPartner.java | 2 +- .../dsv/scipro/report/GradingReportTemplate.java | 15 +++++++-------- .../su/dsv/scipro/system/ProjectTypeSettings.java | 7 ++++--- .../V388__harmonize_table_attribute_name.sql | 7 ++----- 5 files changed, 15 insertions(+), 17 deletions(-) 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 878d6a166f..d7c720605a 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 @@ -43,6 +43,7 @@ public class Idea extends DomainObject { private Set ideaParticipations = new HashSet<>(); @ManyToOne(optional = true) + @JoinColumn(name = "application_period_id") private ApplicationPeriod applicationPeriod; @Column(nullable = false, length = TITLE_LENGTH) 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 b182664bc5..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 @@ -39,7 +39,7 @@ public class ProjectPartner extends DomainObject { private ApplicationPeriod applicationPeriod; @Lob - @Basic(optional=false) + @Column(name = "info_text", nullable=false) private String infotext; @Basic(optional = false) 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 c9b395d30f..e2fae329ab 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,27 +1,26 @@ package se.su.dsv.scipro.report; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; - 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 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 java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; + @Entity @Table(name = "grading_report_template") public class GradingReportTemplate extends DomainObject { @@ -31,7 +30,7 @@ public class GradingReportTemplate extends DomainObject { private Long id; @OneToOne(optional = false) - @Column(name = "proejct_type_id") + @JoinColumn(name = "proejct_type_id") private ProjectType projectType; @OneToMany(mappedBy = "gradingReportTemplate", cascade = {CascadeType.ALL}) 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 7218c073e6..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,16 +1,17 @@ package se.su.dsv.scipro.system; -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.JoinColumn; import jakarta.persistence.OneToOne; import jakarta.persistence.Table; +import java.util.Objects; + @Entity @Cacheable(true) @Table(name="project_type_settings") @@ -24,7 +25,7 @@ public class ProjectTypeSettings extends DomainObject { private Long id; @OneToOne(optional = false) - @Column(name = "project_type_id") + @JoinColumn(name = "project_type_id") private ProjectType projectType; /* diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql index ddcaa4fd31..c77c8b5e36 100644 --- a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql @@ -781,13 +781,10 @@ 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 constraint pk_project_type_project_module - primary key(project_type_id, 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_oxqyb1t8jo7cq2fx8j9slvloa`; 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`; @@ -1190,7 +1187,7 @@ alter table `milestone_activity_template_project_type` -- 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 (fk_ct_pt_project_type_id) references 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 -- 2.39.5 From a9a2ee163182a7352b2492568789a013a00f8c89 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 10 Jul 2024 15:37:50 +0200 Subject: [PATCH 44/99] task/3382: Correct JPA-mapping to defaultProjectTypeFilter in UserProfile. --- .../se/su/dsv/scipro/settings/dataobjects/UserProfile.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 fda46e94d0..72cf2ce319 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 @@ -74,7 +74,9 @@ public class UserProfile extends DomainObject { @ManyToMany @JoinTable(name = "user_profile_project_type", - joinColumns = @JoinColumn(name = "user_profile_id", referencedColumnName = "id")) + joinColumns = @JoinColumn(name = "user_profile_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "project_type_id", referencedColumnName = "id") + ) private Collection defaultProjectTypeFilter = new ArrayList<>(); @Override -- 2.39.5 From ac3f8e16e3c3eba19f21448b4f48369e54a99462 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 10:15:37 +0200 Subject: [PATCH 45/99] task/3382: rename SQL script file to later version because of changes of database in develop branch. --- ...ttribute_name.sql => V389__harmonize_table_attribute_name.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/resources/db/migration/{V388__harmonize_table_attribute_name.sql => V389__harmonize_table_attribute_name.sql} (100%) diff --git a/core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql similarity index 100% rename from core/src/main/resources/db/migration/V388__harmonize_table_attribute_name.sql rename to core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql -- 2.39.5 From 1bbb178822d15b8cf932fc0c6f10a870396c6dd5 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 10:59:14 +0200 Subject: [PATCH 46/99] task/3382: fix table project_user_note and JPA-mapping at entity class GradingReportTemplate Rename foreign keys of table project_user_note and fixed a typo in JPA-mapping of entity class GradingReportTemplate. --- .../scipro/report/GradingReportTemplate.java | 2 +- .../V389__harmonize_table_attribute_name.sql | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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 e2fae329ab..e6e8256298 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 @@ -30,7 +30,7 @@ public class GradingReportTemplate extends DomainObject { private Long id; @OneToOne(optional = false) - @JoinColumn(name = "proejct_type_id") + @JoinColumn(name = "project_type_id") private ProjectType projectType; @OneToMany(mappedBy = "gradingReportTemplate", cascade = {CascadeType.ALL}) diff --git a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index c77c8b5e36..54e705591c 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1220,6 +1220,35 @@ alter table `user_profile_project_type` foreign key (project_type_id) references project_type (id) on delete cascade on update cascade; +/* + * Step 7: checklist related tables + */ + + + + + +/* + * Step X: 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; + + /* Useful SQL -- 2.39.5 From aa45adc5cb464d186e4f607a96d1f26af832355d Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 12:47:00 +0200 Subject: [PATCH 47/99] task/3382: use single import statement Use single import statement for DeliveryConfiguration and Program. Missed it earlier. --- .../settings/entities/DeliveryConfiguration.java | 11 +++++++++-- .../main/java/se/su/dsv/scipro/system/Program.java | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) 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 ee89bcf5e9..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,10 +1,17 @@ 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 = { 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 63c2d6acd4..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,8 +1,14 @@ 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") public class Program extends DomainObject { -- 2.39.5 From ed50cae208ee7444f3917972489b42e904b19b77 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 14:10:19 +0200 Subject: [PATCH 48/99] task/3382: fixed a few checklist related tables and their entity class Fixed a few tables related to checklist, such as: * checklist * checklist_category * checklist_checklist_category * checklist_user_last_open_date * checklist_checklist_question JPA-mapping is located at entity class Checklist and ChecklistCategory. --- .../se/su/dsv/scipro/checklist/Checklist.java | 39 +++++++- .../scipro/checklist/ChecklistCategory.java | 18 ++-- .../V389__harmonize_table_attribute_name.sql | 91 +++++++++++++++++++ 3 files changed, 138 insertions(+), 10 deletions(-) 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..99c6ff8650 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,13 +1,35 @@ package se.su.dsv.scipro.checklist; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +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.MapKeyColumn; +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.*; - @Entity @Table(name = "checklist") @Cacheable(true) @@ -17,6 +39,7 @@ public class Checklist extends DomainObject { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic @Column(nullable = false) private String name; @@ -28,15 +51,25 @@ 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") + @MapKeyColumn(name = "user_id") private Map userLastOpenDate = new HashMap<>(); protected Checklist() { 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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 54e705591c..6094c7b31c 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1224,6 +1224,97 @@ alter table `user_profile_project_type` * 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; + + + + -- 2.39.5 From d21601044c10e676a109cab8d8a87c6b5e72f140 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 14:17:06 +0200 Subject: [PATCH 49/99] task/3382: fixed a typo One value of ChecklistAnswerEnum shall be NOT_APPLICABLE, but it's wrongly spelled as NOT_APLICABLE. --- .../java/se/su/dsv/scipro/checklist/ChecklistAnswerEnum.java | 2 +- view/src/main/java/se/su/dsv/scipro/checklists/AnswerPanel.java | 2 +- .../se/su/dsv/scipro/checklists/ChecklistOverviewPanel.java | 2 +- .../java/se/su/dsv/scipro/checklists/TrafficLightPanel.java | 2 +- .../main/java/se/su/dsv/scipro/peer/DisplayQuestionPanel.java | 2 +- .../java/se/su/dsv/scipro/checklists/TrafficLightPanelTest.java | 2 +- .../java/se/su/dsv/scipro/peer/DisplayQuestionPanelTest.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) 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/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/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/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/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 -- 2.39.5 From bb1ded097776a24bc6366504be523819f9e88f54 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 14:38:54 +0200 Subject: [PATCH 50/99] task/3382: fixed checklist question/answer tables and JPA-mappings Fixed following tables: * checklist_question * checklist_answer * checklist_question_checklist_answer Their related JPA-mappings are fixed in entity class ChecklistQuestion and ChecklistAnswer as well. --- .../dsv/scipro/checklist/ChecklistAnswer.java | 20 +++++++++--- .../scipro/checklist/ChecklistQuestion.java | 29 +++++++++++++---- .../V389__harmonize_table_attribute_name.sql | 32 +++++++++++++++++++ 3 files changed, 70 insertions(+), 11 deletions(-) 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..28e61ce945 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,11 +1,22 @@ package se.su.dsv.scipro.checklist; +import java.util.Objects; + +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 { @@ -14,10 +25,11 @@ public class ChecklistAnswer extends DomainObject { private Long id; @Enumerated(EnumType.STRING) - @Column(nullable = false) + @Column(name = "answer", nullable = false) private ChecklistAnswerEnum answer; @ManyToOne(optional = false) + @JoinColumn(name = "user_id") private User user; @Lob 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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 6094c7b31c..f258f13ea8 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1312,9 +1312,41 @@ alter table `checklist` 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; + +-- table: checklist_question + +alter table `checklist_question` rename column `questionNumber` to `question_number`; -- 2.39.5 From d62ad0817affe9e3d5504c3394e0431c81d9c810 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 15:20:45 +0200 Subject: [PATCH 51/99] task/3382: fixed checklist template related tables and JPA-mappings Fixed following tables: * checklist_template * checklist_template_question * checklist_template_checklist_category Their related JPA-mappings are fixed in entity class ChecklistTemplate. --- .../scipro/checklist/ChecklistTemplate.java | 36 +++++++++++--- .../V389__harmonize_table_attribute_name.sql | 47 +++++++++++++++++++ 2 files changed, 76 insertions(+), 7 deletions(-) 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 415e26b074..255bf21078 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,12 +1,30 @@ package se.su.dsv.scipro.checklist; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +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.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.Lob; +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.*; - @Entity @Table(name = "checklist_template") public class ChecklistTemplate extends DomainObject { @@ -23,20 +41,24 @@ public class ChecklistTemplate extends DomainObject { @Basic(optional = true) private String description; - @Column + @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 = "user_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 diff --git a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index f258f13ea8..305601902f 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1348,6 +1348,53 @@ alter table `checklist_answer` 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 `user_id`; +alter table `checklist_template` rename column `templateNumber` to `template_number`; + +alter table `checklist_template` + add constraint fk_checklist_template_user_id + foreign key (user_id) references user (id) + on delete cascade on update cascade; + -- 2.39.5 From f2ae73d35cee8d94ef6eb3453eefc99d2bdbe656 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 15:50:25 +0200 Subject: [PATCH 52/99] task/3382: improve helper SQL-script. --- .../db/migration/V389__harmonize_table_attribute_name.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 305601902f..85767d2d67 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1448,4 +1448,8 @@ select table_name, column_name, constraint_name, referenced_table_name, referenc from information_schema.key_column_usage where table_schema = 'tozh4728' and table_name = 'ActivityTemplate' and constraint_name != 'PRIMARY'; +select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name + from information_schema.key_column_usage +where table_schema = 'tozh4728' and constraint_name != 'PRIMARY' order by constraint_name; + */ \ No newline at end of file -- 2.39.5 From 9b30164faf6795b27cc56ef3f92b5a0a8bb08d77 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 15:58:09 +0200 Subject: [PATCH 53/99] task/3382: Remove @Lob annotation to get rid of IntelliJ warnng. --- .../main/java/se/su/dsv/scipro/checklist/ChecklistTemplate.java | 1 - 1 file changed, 1 deletion(-) 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 255bf21078..da5381aa9c 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 @@ -44,7 +44,6 @@ public class ChecklistTemplate extends DomainObject { @Column(name = "template_number") private int templateNumber = DEFAULT_TEMPLATE_NUMBER; - @Lob @ElementCollection @CollectionTable(name = "checklist_template_question", joinColumns = @JoinColumn(name = "checklist_template_id")) -- 2.39.5 From 8650278efc210eabb346d956911b31c299e5f049 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 11 Jul 2024 16:30:14 +0200 Subject: [PATCH 54/99] task/3382: JPA-mapping shall use @MapKeyJoinColumn for mapping from talbe checklist to checklist_user_last_open_date. --- .../se/su/dsv/scipro/checklist/Checklist.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 99c6ff8650..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,5 @@ package se.su.dsv.scipro.checklist; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - import jakarta.persistence.Basic; import jakarta.persistence.Cacheable; import jakarta.persistence.CascadeType; @@ -22,14 +15,20 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; -import jakarta.persistence.MapKeyColumn; +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 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") @Cacheable(true) @@ -69,7 +68,8 @@ public class Checklist extends DomainObject { @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "checklist_user_last_open_date", joinColumns = @JoinColumn(name = "checklist_id")) @Column(name = "last_open_date") - @MapKeyColumn(name = "user_id") + @SuppressWarnings("JpaDataSourceORMInspection") // false warning from IntelliJ for the @MapKeyJoinColumn + @MapKeyJoinColumn(name = "user_id") private Map userLastOpenDate = new HashMap<>(); protected Checklist() { -- 2.39.5 From f5f85f148663ce400464ff457ed585e2ea8c69af Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 8 Aug 2024 12:11:01 +0200 Subject: [PATCH 55/99] task/3382: Fixed Survey related tables and JPA-mappings --- .../se/su/dsv/scipro/survey/Question.java | 17 +++- .../java/se/su/dsv/scipro/survey/Survey.java | 11 ++- .../se/su/dsv/scipro/survey/SurveyAnswer.java | 5 +- .../V389__harmonize_table_attribute_name.sql | 91 +++++++++++++++++++ 4 files changed, 121 insertions(+), 3 deletions(-) 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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 85767d2d67..707d2177fb 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1395,6 +1395,94 @@ alter table `checklist_template` foreign key (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; + + + + + + + + @@ -1420,6 +1508,9 @@ alter table `project_user_note` + + + /* Useful SQL >>> SQL query for FK-to: -- 2.39.5 From 52cb71d3d24bce897126102150044dd4fa2654d1 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 9 Aug 2024 14:37:20 +0200 Subject: [PATCH 56/99] task/3382: Fixed keyword and research area related tables and JPA-mappings --- .../java/se/su/dsv/scipro/match/Idea.java | 48 ++++++- .../java/se/su/dsv/scipro/match/Keyword.java | 20 ++- .../se/su/dsv/scipro/project/Project.java | 44 ++++++- .../se/su/dsv/scipro/system/ResearchArea.java | 14 +- .../V389__harmonize_table_attribute_name.sql | 121 ++++++++++++++++++ 5 files changed, 231 insertions(+), 16 deletions(-) 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 d7c720605a..0402cda571 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,13 +1,49 @@ 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 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 @@ -23,7 +59,7 @@ public class Idea extends DomainObject { private Long id; @ManyToOne(optional = false) - @JoinColumn(name = "project_type_id") + @JoinColumn(name = "project_type_id", referencedColumnName = "id") private ProjectType projectType; @Enumerated(EnumType.STRING) @@ -43,13 +79,14 @@ public class Idea extends DomainObject { private Set ideaParticipations = new HashSet<>(); @ManyToOne(optional = true) - @JoinColumn(name = "application_period_id") + @JoinColumn(name = "application_period_id", referencedColumnName = "id") private ApplicationPeriod applicationPeriod; @Column(nullable = false, length = TITLE_LENGTH) private String title; @ManyToOne(optional = true) + @JoinColumn(name = "research_area_id", referencedColumnName = "id") private ResearchArea researchArea; @ElementCollection @@ -72,6 +109,9 @@ public class Idea extends DomainObject { private TholanderBox tholanderBox = new TholanderBox(); @ManyToMany + @JoinTable(name="idea_keyword", + joinColumns = @JoinColumn(name = "idea_id", referencedColumnName = "id"), + inverseJoinColumns = @JoinColumn(name = "keyword_id", referencedColumnName = "id")) private Set keywords = new HashSet<>(); @OneToOne 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/project/Project.java b/core/src/main/java/se/su/dsv/scipro/project/Project.java index 55684b91c0..d143125259 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,45 @@ 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 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 @@ -22,11 +54,12 @@ public class Project extends DomainObject { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic @Column(unique = true) private Integer identifier; - @Column(length = TITLE_MAX_LENGTH) @Basic(optional = false) + @Column(length = TITLE_MAX_LENGTH) private String title; @Basic(optional = false) @@ -51,7 +84,7 @@ public class Project extends DomainObject { @ManyToOne(optional = false) @QueryInit({"unit"}) - @JoinColumn(name = "supervisor_id") + @JoinColumn(name = "supervisor_id", referencedColumnName = "id") private User headSupervisor; @Enumerated(EnumType.STRING) @@ -67,7 +100,7 @@ public class Project extends DomainObject { private String stateOfMindReason; @ManyToOne(optional = false) - @JoinColumn(name = "project_type_id") + @JoinColumn(name = "project_type_id", referencedColumnName = "id") private ProjectType projectType; @Embedded @@ -81,6 +114,7 @@ public class Project extends DomainObject { private int credits; @ManyToOne(optional = true) + @JoinColumn(name = "research_area_id", referencedColumnName = "id") private ResearchArea researchArea; @Enumerated(EnumType.STRING) 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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 707d2177fb..21e5601e4e 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1476,7 +1476,128 @@ alter table `survey_answer` 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; -- 2.39.5 From cac874af886d206e33e28d3c7b34287ef13b318e Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Fri, 9 Aug 2024 14:52:04 +0200 Subject: [PATCH 57/99] task/3382: Fixed JPA-mapping annotation from User to ResearchArea --- core/src/main/java/se/su/dsv/scipro/system/User.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 f1e5b451f4..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 @@ -94,7 +94,9 @@ public class User extends LazyDeletableDomainObject { 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) -- 2.39.5 From b05298883906bf5afabec04ccc5d9cb830776d3f Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 26 Aug 2024 10:57:29 +0200 Subject: [PATCH 58/99] task/3382: Fixed idea related tables and JPA-mappings --- .../se/su/dsv/scipro/match/FirstMeeting.java | 104 +++++++---- .../java/se/su/dsv/scipro/match/Idea.java | 174 +++++++++++------- .../se/su/dsv/scipro/match/IdeaExport.java | 67 ++++--- .../dsv/scipro/match/IdeaParticipation.java | 112 +++++++---- .../java/se/su/dsv/scipro/match/Match.java | 75 +++++--- .../su/dsv/scipro/match/PreliminaryMatch.java | 78 +++++--- .../se/su/dsv/scipro/project/Project.java | 8 +- .../V389__harmonize_table_attribute_name.sql | 149 +++++++++++++++ 8 files changed, 556 insertions(+), 211 deletions(-) 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 0402cda571..ef171c6458 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 @@ -50,96 +50,137 @@ import java.util.stream.Collectors; @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; + @Basic + @Column(nullable = true, length = DESCRIPTION_LENGTH) + private String description; + + @Basic + @Column(nullable = true, length = PREREQUISITES_LENGTH) + private String prerequisites; + + @Basic + @Column(nullable = false, length = TITLE_LENGTH) + private String title; + + @Basic + @Enumerated(EnumType.STRING) + 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(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(); + + // ---------------------------------------------------------------------------------- + // 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 = "match_id", referencedColumnName = "id") + @QueryInit({"supervisor.user", "supervisor.unit"}) + private Match match; + + @OneToOne + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + @ManyToOne(optional = false) @JoinColumn(name = "project_type_id", referencedColumnName = "id") private ProjectType projectType; - @Enumerated(EnumType.STRING) - private Type type; - - @ManyToOne(optional = false) - private User creator; - - @Column(nullable = true, length = DESCRIPTION_LENGTH) - private String description; - - @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) - @JoinColumn(name = "application_period_id", referencedColumnName = "id") - private ApplicationPeriod applicationPeriod; - - @Column(nullable = false, length = TITLE_LENGTH) - private String title; - @ManyToOne(optional = true) @JoinColumn(name = "research_area_id", referencedColumnName = "id") private ResearchArea researchArea; - @ElementCollection - @CollectionTable(name = "idea_language") - @Column(name = "language") - @Enumerated(EnumType.STRING) - private Set languages = EnumSet.noneOf(Language.class); - - @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)) - }) - private Watson watson; - - @Embedded - private TholanderBox tholanderBox = new TholanderBox(); + // ---------------------------------------------------------------------------------- + // @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<>(); - @OneToOne - private Project project; + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing this table "idea" + // ---------------------------------------------------------------------------------- - @OneToOne(mappedBy = "idea", orphanRemoval = true, optional = true) - private FirstMeeting firstMeeting; + // 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; @@ -490,7 +531,9 @@ public class Idea extends DomainObject { public String toString() { return "Student idea"; } - }, SUPERVISOR { + }, + + SUPERVISOR { @Override public String toString() { return "Supervisor idea"; @@ -505,18 +548,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..e0ee0aeeb6 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,115 @@ package se.su.dsv.scipro.match; +import jakarta.persistence.AssociationOverride; +import jakarta.persistence.AssociationOverrides; +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 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 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/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/project/Project.java b/core/src/main/java/se/su/dsv/scipro/project/Project.java index d143125259..ef9404b880 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 @@ -26,7 +26,13 @@ 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 java.time.LocalDate; import java.util.ArrayList; diff --git a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 21e5601e4e..df0240085c 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1599,11 +1599,160 @@ alter table `keyword_research_area` 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` 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 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; -- 2.39.5 From 74f0933fbb5e40ed7bd1ae885abf00b656dc45c9 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 2 Sep 2024 12:06:49 +0200 Subject: [PATCH 59/99] task/3382: Fixed activity related tables and JPA-mappings --- .../su/dsv/scipro/activityplan/Activity.java | 196 +++++++++++------- .../dsv/scipro/activityplan/ActivityPlan.java | 110 ++++++---- .../activityplan/ActivityPlanTemplate.java | 2 +- .../firstmeeting/ProjectFirstMeeting.java | 54 +++-- .../ActivityFinalSeminar.java | 42 +++- .../activityforum/ActivityThread.java | 46 +++- .../java/se/su/dsv/scipro/match/Idea.java | 2 +- .../V389__harmonize_table_attribute_name.sql | 142 ++++++++++++- 8 files changed, 441 insertions(+), 153 deletions(-) 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..898c74ef76 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,165 @@ 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 { + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @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; - + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (activity) referencing other tables. + // ---------------------------------------------------------------------------------- + @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 = "file_upload_reference_id", referencedColumnName = "id") + private FileReference fileUpload; + + // ---------------------------------------------------------------------------------- + // constructor + // ---------------------------------------------------------------------------------- public Activity() { this.title = ""; this.description = ""; } - @Override - public String toString(){ - return "Event: "+ getTitle()+"@"+getDate(); - } - - @Override + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- + @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; + } + + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -144,15 +169,30 @@ public class Activity extends LazyDeletableDomainObject { && Objects.equals(this.getId(), other.getId()); } + @Override + public int hashCode() { + return Objects.hashCode(getId()); + } + + @Override + public String toString(){ + return "Event: "+ getTitle()+"@"+getDate(); + } + protected boolean canEqual(final Object other) { return other instanceof Activity; } - @Override - public int hashCode() { - return Objects.hashCode(getId()); + // ---------------------------------------------------------------------------------- + // static methods + // ---------------------------------------------------------------------------------- + public static IActivityPlan builder(){ + return new Builder(); } + // ---------------------------------------------------------------------------------- + // nested classes + // ---------------------------------------------------------------------------------- public static class ByDateComparator implements Comparator, Serializable { @Override public int compare(Activity o1, Activity o2) { @@ -209,10 +249,6 @@ public class Activity extends LazyDeletableDomainObject { } } - public static IActivityPlan builder(){ - return new Builder(); - } - public interface IActivityPlan { IDate activityPlan(ActivityPlan activityPlan); } 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..79cc1b599a 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,93 @@ 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 { + // ---------------------------------------------------------------------------------- + // basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - + + @Basic + @Column(name = "start_date") + private Date startDate; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of foreign keys in this table (activity_plan) referencing other tables. + // ---------------------------------------------------------------------------------- + @OneToOne(optional=false) + @JoinColumn(name = "project_id", referencedColumnName = "id") + private Project project; + + // ---------------------------------------------------------------------------------- + // JPA-mappings of other tables referencing to this table "activity_plan" + // ---------------------------------------------------------------------------------- @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; + // ---------------------------------------------------------------------------------- + // getters and setters + // ---------------------------------------------------------------------------------- @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; + } + + // ---------------------------------------------------------------------------------- + // other methods + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -74,15 +100,31 @@ 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; + } + + // ---------------------------------------------------------------------------------- + // static methods + // ---------------------------------------------------------------------------------- + public static IProject builder() { + return new Builder(); + } + + // ---------------------------------------------------------------------------------- + // nested classes + // ---------------------------------------------------------------------------------- private static class Builder implements IProject, IBuild { private Project project; @@ -100,10 +142,6 @@ public class ActivityPlan extends DomainObject { } } - public static IProject builder() { - return new Builder(); - } - public interface IProject { IBuild project(Project project); } 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 d02768de8c..ff0bf1be27 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 @@ -24,8 +24,8 @@ import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.User; @Entity -@Cacheable(true) @Table(name = "activity_plan_template") +@Cacheable(true) public class ActivityPlanTemplate extends DomainObject { @Id 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/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/match/Idea.java b/core/src/main/java/se/su/dsv/scipro/match/Idea.java index ef171c6458..7f28952e98 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 @@ -149,7 +149,7 @@ public class Idea extends DomainObject { private Set keywords = new HashSet<>(); // ---------------------------------------------------------------------------------- - // JPA-mappings of other tables referencing this table "idea" + // JPA-mappings of other tables referencing to this table "idea" // ---------------------------------------------------------------------------------- // from table idea_language diff --git a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index df0240085c..f3793ce644 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1754,6 +1754,143 @@ alter table `idea_student` 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 `project_first_meeting_ibfk_1`; + +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 `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_file_reference_id` + foreign key (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: XXX related tables + * + + + + /* @@ -1776,11 +1913,6 @@ alter table `project_user_note` foreign key (user_id) references user (id) on delete cascade on update cascade; - - - - - /* Useful SQL >>> SQL query for FK-to: -- 2.39.5 From 60732cd0c38e6ec4ff3be884a149e0baeba9e131 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 4 Sep 2024 10:20:37 +0200 Subject: [PATCH 60/99] task/3382: Fixed peer request related tables and JPA-mappings --- .../java/se/su/dsv/scipro/peer/Answer.java | 108 ++++--- .../se/su/dsv/scipro/peer/PeerRequest.java | 238 +++++++++------- .../se/su/dsv/scipro/peer/PeerReview.java | 267 ++++++++++-------- .../V389__harmonize_table_attribute_name.sql | 105 ++++++- 4 files changed, 459 insertions(+), 259 deletions(-) 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/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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index f3793ce644..7baecf0162 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1885,11 +1885,110 @@ alter table `activity_final_seminar` on delete cascade on update cascade; /* - * Step 12: XXX related tables - * + * 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 cascade 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; @@ -1939,7 +2038,7 @@ order by table_name; select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name from information_schema.key_column_usage -where table_schema = 'tozh4728' and table_name = 'ActivityTemplate' and constraint_name != 'PRIMARY'; +where table_schema = 'tozh4728' and table_name = 'peer_request' and constraint_name != 'PRIMARY'; select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name from information_schema.key_column_usage -- 2.39.5 From da93ff063861ea483cbbf44d9473196732ea48dd Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 11 Sep 2024 16:14:03 +0200 Subject: [PATCH 61/99] task/3382: Fixed milestone related tables and JPA-mappings --- .../java/se/su/dsv/scipro/match/Idea.java | 6 +- .../milestones/dataobjects/Milestone.java | 77 +++++--- .../MilestoneActivityTemplate.java | 166 +++++++++++------- .../dataobjects/MilestonePhaseTemplate.java | 69 +++++--- .../java/se/su/dsv/scipro/system/Event.java | 28 ++- .../V389__harmonize_table_attribute_name.sql | 90 +++++++++- 6 files changed, 320 insertions(+), 116 deletions(-) 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 7f28952e98..30a9029388 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 @@ -33,7 +33,11 @@ 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 java.time.LocalDate; import java.util.ArrayList; 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 247293df64..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,22 +31,55 @@ 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( name = "milestone_activity_template_project_type", @@ -42,20 +88,9 @@ public class MilestoneActivityTemplate extends LazyDeletableDomainObject { ) 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() { } @@ -69,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; @@ -82,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; @@ -177,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/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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 7baecf0162..2048c19323 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -1990,10 +1990,98 @@ alter table `answer` 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 + */ + + + + + + + + /* - * Step X: Many-to-Many tables between project and user. + * Step XX: Many-to-Many tables between project and user. */ -- table: project_user_note (new changes from develop branch) -- 2.39.5 From e867dfcde9f2012b16a4943f61fe7dd53a43ad6a Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 23 Sep 2024 12:33:44 +0200 Subject: [PATCH 62/99] task/3382: Fixed final seminar related tables and JPA-mappings --- .../dsv/scipro/finalseminar/FinalSeminar.java | 461 ++++++++++-------- .../FinalSeminarActiveParticipation.java | 28 +- .../finalseminar/FinalSeminarOpposition.java | 112 +++-- .../FinalSeminarParticipation.java | 107 ++-- .../finalseminar/FinalSeminarRespondent.java | 8 +- .../V389__harmonize_table_attribute_name.sql | 147 +++++- 6 files changed, 558 insertions(+), 305 deletions(-) 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..08cb2a8f47 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 = "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,82 @@ 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 +309,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 +386,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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 2048c19323..9fa06d926d 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2071,13 +2071,142 @@ create index idx_milestone_phase_template_deleted on milestone_phase_template (d * 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 `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_file_reference_id + foreign key (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; /* @@ -2124,12 +2253,18 @@ order by table_name; >>> Show foreign keys -select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage -where table_schema = 'tozh4728' and table_name = 'peer_request' and constraint_name != 'PRIMARY'; + -- show foreign keys for a simple table + select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name + from information_schema.key_column_usage + where table_schema = 'tozh4728' and + table_name = 'final_seminar_respondent' and + constraint_name != 'PRIMARY'; -select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage -where table_schema = 'tozh4728' and constraint_name != 'PRIMARY' order by constraint_name; + -- show foreign keys for all tables + select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name + from information_schema.key_column_usage + where table_schema = 'tozh4728' and + constraint_name != 'PRIMARY' + order by constraint_name; */ \ No newline at end of file -- 2.39.5 From 5a92cbbce9aae61a4be2ec6674b8febd6f886479 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 26 Sep 2024 13:21:36 +0200 Subject: [PATCH 63/99] task/3382: Fixed report, criterion and opposition_report related tables and JPA-mappings --- .../dsv/scipro/finalseminar/FinalSeminar.java | 1 + .../dsv/scipro/report/AbstractCriterion.java | 38 +++++-- .../dsv/scipro/report/AttachmentReport.java | 26 +++-- .../se/su/dsv/scipro/report/Criterion.java | 96 ++++++++++------- .../dsv/scipro/report/OppositionReport.java | 102 +++++++++++------- .../java/se/su/dsv/scipro/report/Report.java | 77 ++++++++----- .../V389__harmonize_table_attribute_name.sql | 90 +++++++++++++++- 7 files changed, 311 insertions(+), 119 deletions(-) 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 08cb2a8f47..ab5fc08dbb 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 @@ -294,6 +294,7 @@ public class FinalSeminar extends LazyDeletableDomainObject { ", maxParticipants=" + this.getMaxParticipants() + ", creationReason=" + this.getCreationReason() + ")"; } + // ---------------------------------------------------------------------------------- // Other Methods // ---------------------------------------------------------------------------------- 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 68d6b1b276..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,5 +1,6 @@ package se.su.dsv.scipro.report; +import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -14,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 @Column(name = "title_sv", nullable = false) private String title; + @Basic @Column(name = "title_en", nullable = false) private String titleEn; + @Basic @Column(name = "sort_order", nullable = false) private Integer sortOrder; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected AbstractCriterion() { } @@ -36,6 +46,9 @@ public abstract class AbstractCriterion extends DomainObject { this.sortOrder = sortOrder; } + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- @Override public Long getId() { return this.id; @@ -49,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; @@ -70,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()); @@ -84,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/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/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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 9fa06d926d..eda0c1399b 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2208,6 +2208,87 @@ alter table `final_seminar_respondent` 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; + +-- todo: table: GradingCriterionPoint, except foreign key to becoming table grading_criterion + +-- todo: table: GradingCriterion, except foreign key to becoming table grading_report + +-- todo: add foreign key reference from grading_criterion_point to grading_criterion + +-- todo: table: SupervisorGradingReport, except foreign key to becoming table grading_report + +-- todo: table: ReviewerGradingReport, except foreign key to becoming table grading_report + +-- todo: table: GradingReport + +-- todo: add foreign key reference from reviewer_grading_report to grading_report + +-- todo: add foreign key reference from supervisor_grading_report to grading_report + +-- todo: add foreign key reference from grading_criterion to grading_report + /* * Step XX: Many-to-Many tables between project and user. @@ -2257,7 +2338,7 @@ order by table_name; select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name from information_schema.key_column_usage where table_schema = 'tozh4728' and - table_name = 'final_seminar_respondent' and + table_name = 'criterion' and constraint_name != 'PRIMARY'; -- show foreign keys for all tables @@ -2265,6 +2346,11 @@ order by table_name; from information_schema.key_column_usage where table_schema = 'tozh4728' and constraint_name != 'PRIMARY' - order by constraint_name; + order by table_name collate utf8_nopad_bin, constraint_name collate utf8_nopad_bin; + + +> Show collation; + + */ \ No newline at end of file -- 2.39.5 From 065601aa037ac81b41aef96475941d7008345825 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 16 Oct 2024 14:46:17 +0200 Subject: [PATCH 64/99] task/3382: Fixed GradingCriterionPoint, GradingCriterion, SupervisorGradingReport, ReviewerGradingReport and GradingReport related tables and JPA-mappings --- .../report/AbstractGradingCriterion.java | 42 +++-- .../report/AbstractGradingCriterionPoint.java | 60 ++++--- .../dsv/scipro/report/GradingCriterion.java | 163 +++++++++++------- .../scipro/report/GradingCriterionPoint.java | 52 ++++-- .../su/dsv/scipro/report/GradingReport.java | 89 +++++++--- .../report/SupervisorGradingReport.java | 93 +++++----- .../V389__harmonize_table_attribute_name.sql | 106 +++++++++++- 7 files changed, 414 insertions(+), 191 deletions(-) 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 29bcfc0360..39ea7f1166 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 @@ -7,12 +7,20 @@ import jakarta.persistence.MappedSuperclass; @MappedSuperclass public abstract class AbstractGradingCriterion extends AbstractCriterion { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- + @Basic @Column(name = "points_required_to_pass", nullable = false) protected int pointsRequiredToPass; @Basic + @Column(name = "fx") private boolean fx = true; + // ---------------------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------------------- protected AbstractGradingCriterion() { } @@ -22,11 +30,9 @@ public abstract class AbstractGradingCriterion extends AbstractCriterion { this.pointsRequiredToPass = pointsRequiredToPass; } - public abstract boolean isProjectCriterion(); - - public abstract boolean isIndividualCriterion(); - - public abstract int getMaxPoints(); + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- public int getPointsRequiredToPass() { return this.pointsRequiredToPass; @@ -36,6 +42,13 @@ public abstract class AbstractGradingCriterion extends AbstractCriterion { return this.fx; } + public void setFx(boolean fx) { + this.fx = fx; + } + + // ---------------------------------------------------------------------------------- + // Methods Common To All Objects + // ---------------------------------------------------------------------------------- @Override public boolean equals(final Object o) { if (o == this) return true; @@ -47,11 +60,6 @@ public abstract class AbstractGradingCriterion extends AbstractCriterion { && this.isFx() == other.isFx(); } - @Override - protected boolean canEqual(final Object other) { - return other instanceof AbstractGradingCriterion; - } - @Override public int hashCode() { final int PRIME = 59; @@ -66,7 +74,17 @@ public abstract class AbstractGradingCriterion extends AbstractCriterion { return "AbstractGradingCriterion(pointsRequiredToPass=" + this.getPointsRequiredToPass() + ", fx=" + this.isFx() + ")"; } - public void setFx(boolean fx) { - this.fx = fx; + // ---------------------------------------------------------------------------------- + // 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(); } 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 5bcca1b670..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 @@ -13,13 +13,19 @@ 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 @@ -30,46 +36,51 @@ public abstract class AbstractGradingCriterionPoint extends DomainObject impleme @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; @@ -83,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()); @@ -96,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/GradingCriterion.java b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterion.java index d54ff820ad..0e9ce20efc 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,6 +1,17 @@ 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; @@ -9,22 +20,38 @@ import java.util.Objects; @Entity @DiscriminatorColumn(name = "type") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@Table(name = "grading_criterion") 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/GradingReport.java b/core/src/main/java/se/su/dsv/scipro/report/GradingReport.java index 4c4b70397c..1b2030dd6c 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 enum Grade { @@ -21,40 +30,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(){ @@ -65,12 +85,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() { @@ -78,6 +94,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(); } @@ -106,7 +137,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/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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index eda0c1399b..d2cbcfc6c6 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2271,24 +2271,112 @@ alter table `criterion` foreign key (report_id) references report (id) on delete cascade on update cascade; --- todo: table: GradingCriterionPoint, except foreign key to becoming table grading_criterion +-- table: GradingCriterionPoint, except foreign key to becoming table grading_criterion --- todo: table: GradingCriterion, except foreign key to becoming table grading_report +alter table `GradingCriterionPoint` drop foreign key `FK_GradingCriterion_id`; --- todo: add foreign key reference from grading_criterion_point to grading_criterion +alter table `GradingCriterionPoint` drop key `FK_GradingCriterion_id`; --- todo: table: SupervisorGradingReport, except foreign key to becoming table grading_report +alter table `GradingCriterionPoint` change `GradingCriterion_id` `grading_criterion_id` bigint(20) not null + after `description_en`; --- todo: table: ReviewerGradingReport, except foreign key to becoming table grading_report +rename table `GradingCriterionPoint` to `grading_criterion_point`; --- todo: table: GradingReport +-- table: GradingCriterion, except foreign key to becoming table grading_report --- todo: add foreign key reference from reviewer_grading_report to grading_report +alter table `GradingCriterion` drop foreign key `FK_k2ynx2lcpdl969alj5nt3f7xx`; --- todo: add foreign key reference from supervisor_grading_report to grading_report +alter table `GradingCriterion` drop key `FK_k2ynx2lcpdl969alj5nt3f7xx`; --- todo: add foreign key reference from grading_criterion to grading_report +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 `fx`; +rename table `GradingCriterion` to `grading_criterion`; + +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; + +-- 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 + */ + +-- todo: /* * Step XX: Many-to-Many tables between project and user. -- 2.39.5 From eb5f948aaa3c7742cb74b33ae7b681b558c10eff Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 23 Oct 2024 13:20:16 +0200 Subject: [PATCH 65/99] task/3382: Fixed project and related JPA-mappings --- .../su/dsv/scipro/grading/ApprovedEvent.java | 47 +- .../grading/NationalSubjectCategory.java | 36 +- .../scipro/grading/PublicationMetadata.java | 57 +- .../su/dsv/scipro/grading/RejectionEvent.java | 59 ++- .../se/su/dsv/scipro/project/Project.java | 498 ++++++++++-------- .../V389__harmonize_table_attribute_name.sql | 105 +++- 6 files changed, 503 insertions(+), 299 deletions(-) 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..1aa51eca5c 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,15 +12,14 @@ 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") private String swedishName; @@ -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..1a5028425d 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,14 +17,13 @@ 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") private String abstractSwedish; @@ -41,10 +40,21 @@ public class PublicationMetadata { @Column(name = "keywords_english") 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/project/Project.java b/core/src/main/java/se/su/dsv/scipro/project/Project.java index ef9404b880..1f338b20d1 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 @@ -56,18 +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; - @Basic - @Column(unique = true) - private Integer identifier; - @Basic(optional = false) - @Column(length = TITLE_MAX_LENGTH) + @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; @@ -76,63 +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", referencedColumnName = "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; + @Basic(optional = true) + @Column(name = "state_of_mind_date") + private Date stateOfMindDate; + + @Basic + @Column(name = "daisy_identifier", unique = true) + private Integer identifier; + + // ---------------------------------------------------------------------------------- + // Embedded JPA-mappings + // ---------------------------------------------------------------------------------- + @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; - @Embedded - @AttributeOverride(name = "name", column = @Column(name = "externalOrganization")) - private ExternalOrganization externalOrganization; - - @Column(name = "fs_rule_exmpt") - private boolean finalSeminarRuleExempted = false; - - @Basic - private int credits; - @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() { @@ -142,12 +182,68 @@ 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() { @@ -158,53 +254,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() { @@ -217,8 +280,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() { @@ -232,11 +331,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; @@ -245,6 +424,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<>(); @@ -281,23 +468,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(); } @@ -330,10 +504,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); } @@ -360,125 +530,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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index d2cbcfc6c6..b5a0ea2001 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2376,10 +2376,96 @@ alter table `grading_criterion` * Step 15: project and related tables */ --- todo: +-- 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 `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` + 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 XX: Many-to-Many tables between project and user. + * Step 16: Many-to-Many tables between project and user. */ -- table: project_user_note (new changes from develop branch) @@ -2398,6 +2484,21 @@ alter table `project_user_note` foreign key (user_id) references user (id) on delete cascade on update cascade; +-- todo: table: project_cosupervisor + + +-- todo: table: project_reviewer + +-- todo: table: project_user + +-- todo: table: grading_history_submissions + +-- todo: table: externallink + +-- todo: table: grade + + + /* Useful SQL >>> SQL query for FK-to: -- 2.39.5 From 62120b1186558e11bc670ae80fb0c9e03ec4c1d9 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 24 Oct 2024 11:53:38 +0200 Subject: [PATCH 66/99] task/3382: Fixed Many-to-Many tables between table project and table user, and related JPA-mappings --- .../dsv/scipro/grading/SubmissionEvent.java | 71 +++++---- .../java/se/su/dsv/scipro/project/Author.java | 65 ++++++--- .../se/su/dsv/scipro/project/Project.java | 3 +- .../dsv/scipro/thesislink/ExternalLink.java | 122 ++++++++++------ .../V389__harmonize_table_attribute_name.sql | 136 ++++++++++++++++-- 5 files changed, 289 insertions(+), 108 deletions(-) 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/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 1f338b20d1..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 @@ -115,7 +115,7 @@ public class Project extends DomainObject { private Integer identifier; // ---------------------------------------------------------------------------------- - // Embedded JPA-mappings + // Embedded JPA-mapping // ---------------------------------------------------------------------------------- @Embedded @AttributeOverride(name = "name", column = @Column(name = "external_organization")) @@ -185,7 +185,6 @@ public class Project extends DomainObject { // ---------------------------------------------------------------------------------- // Properties (Getters and Setters) // ---------------------------------------------------------------------------------- - @Override public Long getId() { return this.id; 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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index b5a0ea2001..42fe6ed70c 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2484,18 +2484,135 @@ alter table `project_user_note` foreign key (user_id) references user (id) on delete cascade on update cascade; --- todo: table: project_cosupervisor +-- table: project_cosupervisor +alter table `project_cosupervisor` drop foreign key `FK_fj57t069dymdrnnhdxcnfvvnn`; +alter table `project_cosupervisor` drop foreign key `FK_18x2poxkt8s2bw9kpr7vbmd5j`; --- todo: table: project_reviewer +alter table `project_cosupervisor` drop key `FK_fj57t069dymdrnnhdxcnfvvnn`; +alter table `project_cosupervisor` drop key `FK_18x2poxkt8s2bw9kpr7vbmd5j`; --- todo: table: project_user +alter table `project_cosupervisor` change `user_id` `user_id` bigint(20) not null after `project_id`; --- todo: table: grading_history_submissions +alter table `project_cosupervisor` + add constraint fk_project_cosupervisor_project_id + foreign key (project_id) references project (id) + on delete cascade on update cascade; --- todo: table: externallink +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; --- todo: table: grade @@ -2527,7 +2644,7 @@ order by table_name; select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name from information_schema.key_column_usage where table_schema = 'tozh4728' and - table_name = 'criterion' and + table_name = 'grade' and constraint_name != 'PRIMARY'; -- show foreign keys for all tables @@ -2537,9 +2654,6 @@ order by table_name; constraint_name != 'PRIMARY' order by table_name collate utf8_nopad_bin, constraint_name collate utf8_nopad_bin; - -> Show collation; - - +>>> Show collation; */ \ No newline at end of file -- 2.39.5 From a76eb0c03c1ac50c223c705c0613c33057ff64b8 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 24 Oct 2024 15:25:12 +0200 Subject: [PATCH 67/99] task/3382: Fixed file_reference & file_description, FinalThesis, project_file and their related JPA-mappings --- .../su/dsv/scipro/file/FileDescription.java | 204 +++++++----- .../se/su/dsv/scipro/file/FileReference.java | 4 +- .../se/su/dsv/scipro/file/ProjectFile.java | 89 +++-- .../dsv/scipro/finalthesis/FinalThesis.java | 315 ++++++++++-------- .../V389__harmonize_table_attribute_name.sql | 97 ++++++ 5 files changed, 447 insertions(+), 262 deletions(-) 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/finalthesis/FinalThesis.java b/core/src/main/java/se/su/dsv/scipro/finalthesis/FinalThesis.java index 894e798a5f..c238089a33 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 = "english_title") + private String englishTitle; - @ManyToOne(optional = true) - @JoinColumn(name = "text_matching_document_reference_id") - private FileReference textMatchingDocument; + @Basic + @Column(name = "swedish_title") + private String swedishTitle; + + @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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 42fe6ed70c..6a115da106 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2613,8 +2613,105 @@ alter table `grade` 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 `englishTitle` `english_title` varchar(255) default null after `version`; +alter table `final_thesis` change `swedishTitle` `swedish_title` varchar(255) default null after `english_title`; +alter table `final_thesis` change `status` `status` varchar(32) not null after `swedish_title`; +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 project_file_ibfk_2; +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 + */ + +-- todo: table: Decision + +-- todo: table: ReviewerApproval /* Useful SQL -- 2.39.5 From de27d3d212e9c5ed965a51bf033d235743e72ffa Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 28 Oct 2024 14:30:50 +0100 Subject: [PATCH 68/99] task/3382: Fixed decision and reviewer_approval and their related JPA-mappings --- .../se/su/dsv/scipro/reviewing/Decision.java | 106 +++++++++++------- .../scipro/reviewing/ReviewerApproval.java | 70 ++++++++---- .../V389__harmonize_table_attribute_name.sql | 61 +++++++++- 3 files changed, 174 insertions(+), 63 deletions(-) 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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 6a115da106..a4a7654105 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2709,9 +2709,66 @@ alter table `project_file` * Step 18: Decision & ReviewerApproval */ --- todo: table: Decision +-- table: Decision --- todo: table: ReviewerApproval +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; /* Useful SQL -- 2.39.5 From c14f9de7e23859892736c91d3b89f3ddaf86797e Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 28 Oct 2024 16:04:05 +0100 Subject: [PATCH 69/99] task/3382: Fixed urkund_submission and plagiarism_request and their related JPA-mappings --- .../scipro/plagiarism/PlagiarismRequest.java | 49 +++-- .../plagiarism/urkund/UrkundSubmission.java | 190 ++++++++++-------- .../V389__harmonize_table_attribute_name.sql | 52 +++++ 3 files changed, 197 insertions(+), 94 deletions(-) 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/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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index a4a7654105..2af85aa93a 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2770,6 +2770,58 @@ alter table `decision` 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 `urkund_submission_ibfk_2`; +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 `plagiarism_request_ibfk_2`; +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; + + /* Useful SQL >>> SQL query for FK-to: -- 2.39.5 From 9f13775096d618bbe3f703abac8a4d2d85caad62 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 30 Oct 2024 08:35:23 +0100 Subject: [PATCH 70/99] task/3382: Fixed mail_event related tables and their related JPA-mappings --- .../java/se/su/dsv/scipro/mail/MailEvent.java | 261 ++++++++++-------- .../java/se/su/dsv/scipro/match/Idea.java | 2 +- .../V389__harmonize_table_attribute_name.sql | 65 +++++ 3 files changed, 211 insertions(+), 117 deletions(-) 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/Idea.java b/core/src/main/java/se/su/dsv/scipro/match/Idea.java index 30a9029388..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 @@ -125,7 +125,7 @@ public class Idea extends DomainObject { private User creator; @OneToOne(optional = true, cascade = CascadeType.ALL) - @JoinColumn(name = "match_id", referencedColumnName = "id") + @JoinColumn(name = "latest_match_id", referencedColumnName = "id") @QueryInit({"supervisor.user", "supervisor.unit"}) private Match match; diff --git a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 2af85aa93a..55688a4701 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2821,6 +2821,71 @@ alter table `plagiarism_request` 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; /* Useful SQL -- 2.39.5 From edd66e148b9a1698adad5ba63a9d94d8489fc3cc Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 30 Oct 2024 09:04:21 +0100 Subject: [PATCH 71/99] task/3382: Fixed project_group, project_group_project and their related JPA-mappings --- .../java/se/su/dsv/scipro/group/Group.java | 182 ++++++++++-------- .../V389__harmonize_table_attribute_name.sql | 42 ++++ 2 files changed, 144 insertions(+), 80 deletions(-) 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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 55688a4701..7de3184163 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2887,6 +2887,48 @@ alter table `mail_event_non_user_recipient` 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: ??? + */ + + + + + /* Useful SQL >>> SQL query for FK-to: -- 2.39.5 From 2d1e04799df0db8b962cadb7aa9cdc6e4bc70d4b Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 30 Oct 2024 10:20:59 +0100 Subject: [PATCH 72/99] task/3382: Fixed thread, forum_post, forum_post_file_description and their related JPA-mappings --- .../scipro/forum/dataobjects/ForumPost.java | 106 ++++++++----- .../scipro/forum/dataobjects/ForumThread.java | 144 +++++++++++------- .../V389__harmonize_table_attribute_name.sql | 47 +++++- 3 files changed, 199 insertions(+), 98 deletions(-) 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/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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 7de3184163..190eb48a98 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2922,11 +2922,56 @@ alter table `project_group_project` on delete cascade on update cascade; /* - * Step 22: ??? + * 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; /* Useful SQL -- 2.39.5 From 9e30f1aa575d36a34d2edc337580bfef39c1c003 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 30 Oct 2024 11:32:39 +0100 Subject: [PATCH 73/99] task/3382: Fixed forum_post_read, project_thread, reviewer_thread, group_thread and their related JPA-mappings --- .../forum/dataobjects/ForumPostReadState.java | 18 +++- .../dataobjects/ForumPostReadStateId.java | 4 +- .../scipro/forum/dataobjects/GroupThread.java | 59 ++++++++---- .../forum/dataobjects/ProjectThread.java | 66 +++++++++---- .../forum/dataobjects/ReviewerThread.java | 65 +++++++++---- .../V389__harmonize_table_attribute_name.sql | 96 +++++++++++++++++++ 6 files changed, 244 insertions(+), 64 deletions(-) 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/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/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 190eb48a98..35b68e9ba5 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -2973,6 +2973,102 @@ alter table `forum_post_file_reference` 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; + /* Useful SQL -- 2.39.5 From 2c775e9e70e5ff27e4566a7a5dd614a12667e949 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 31 Oct 2024 13:23:15 +0100 Subject: [PATCH 74/99] task/3382: Fixed notification_data and related tables and JPA-mappings --- .../notifications/ForumNotification.java | 46 +++++- .../dataobject/Notification.java | 71 +++++++--- .../dataobject/NotificationEvent.java | 97 +++++++++---- .../V389__harmonize_table_attribute_name.sql | 132 ++++++++++++++++++ 4 files changed, 291 insertions(+), 55 deletions(-) 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/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..d9652617de 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,40 +1,103 @@ 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; + // ---------------------------------------------------------------------------------- + // 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() { + + } + + protected NotificationEvent(Notification.Type type) { + this.type = type; + } + + // ---------------------------------------------------------------------------------- + // Properties (Getters and Setters) + // ---------------------------------------------------------------------------------- + @Override + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public abstract Enum getEvent(); + public Notification.Type getType() { + return type; + } + + public void setType(Notification.Type type) { + this.type = type; + } + + + + /** * The title of the entity this event is about. * @@ -50,30 +113,10 @@ public abstract class NotificationEvent extends DomainObject { public abstract DomainObject getEntity(); - protected NotificationEvent() { - } - protected NotificationEvent(Notification.Type type) { - this.type = type; - } - @Override - public Long getId() { - return id; - } - public void setId(Long id) { - this.id = id; - } - - public Notification.Type getType() { - return type; - } - - public void setType(Notification.Type type) { - this.type = type; - } public Collection getNotifications() { return notifications; diff --git a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql index 35b68e9ba5..2a51c8cdf2 100644 --- a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql @@ -3069,6 +3069,138 @@ alter table `project_group_thread` 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_sqjaj3jb6t9lsw1l2p8ex8jnb`; +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; + +-- todo: NotificationEvent, JPA-mapping /* Useful SQL -- 2.39.5 From 2e6d7f24c05c34f9903a70d13c579a2c0c94feb7 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 6 Nov 2024 10:14:56 +0100 Subject: [PATCH 75/99] task/3382: Update SQl-migration version to V390. --- ...ttribute_name.sql => V390__harmonize_table_attribute_name.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/resources/db/migration/{V389__harmonize_table_attribute_name.sql => V390__harmonize_table_attribute_name.sql} (100%) diff --git a/core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql similarity index 100% rename from core/src/main/resources/db/migration/V389__harmonize_table_attribute_name.sql rename to core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql -- 2.39.5 From 63c8da867c29f362fa80efb04935098694f197c5 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 6 Nov 2024 11:40:08 +0100 Subject: [PATCH 76/99] task/3382: Fixed changes required by merging from develop branch --- .../report/AbstractGradingCriterion.java | 189 ++++++++++-------- .../se/su/dsv/scipro/report/GradeLimit.java | 11 +- .../report/GradingCriterionTemplate.java | 4 +- .../scipro/report/GradingReportTemplate.java | 165 +++++++++------ .../V390__harmonize_table_attribute_name.sql | 23 ++- 5 files changed, 240 insertions(+), 152 deletions(-) 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/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/GradingCriterionTemplate.java b/core/src/main/java/se/su/dsv/scipro/report/GradingCriterionTemplate.java index 93a6e047c6..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 @@ -16,9 +16,9 @@ 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; 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..0a6afd4394 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_tempalte" + // ---------------------------------------------------------------------------------- + @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/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 2a51c8cdf2..77136f8df6 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -808,8 +808,27 @@ alter table `project_type_settings` add constraint uk_project_type_settings_proj 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` rename column `projectType_id` to `project_type_id`; +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. */ @@ -2293,7 +2312,7 @@ alter table `GradingCriterion` change `title_en` `title_en` varchar(255) not nul 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 `fx`; +alter table `GradingCriterion` change `gradingReport_id` `grading_report_id` bigint(20) not null after `flag`; rename table `GradingCriterion` to `grading_criterion`; -- 2.39.5 From 04037264609bfe6c07d4c95e57f9405cd0ba5fdf Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 6 Nov 2024 11:45:31 +0100 Subject: [PATCH 77/99] task/3382: Improve comments to NotificationEvent --- .../dataobject/NotificationEvent.java | 76 +++++++++---------- 1 file changed, 37 insertions(+), 39 deletions(-) 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 d9652617de..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 @@ -85,8 +85,6 @@ public abstract class NotificationEvent extends DomainObject { this.id = id; } - public abstract Enum getEvent(); - public Notification.Type getType() { return type; } @@ -95,9 +93,41 @@ public abstract class NotificationEvent extends DomainObject { this.type = type; } + public String getSource() { + return source; + } - + public void setSource(String source) { + this.source = source; + } + public String getAdditionalSource() { + return additionalSource; + } + + public void setAdditionalSource(String additionalSource) { + this.additionalSource = additionalSource; + } + + public User getCausedBy() { + return causedBy; + } + + public void setCausedBy(User user) { + 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. * @@ -113,39 +143,15 @@ public abstract class NotificationEvent extends DomainObject { public abstract DomainObject getEntity(); + public abstract Enum getEvent(); - - - - - public Collection getNotifications() { - return notifications; - } - - public void setNotifications(Collection notifications) { - this.notifications = notifications; - } - - public String getSource() { - return source; - } - - public void setSource(String source) { - this.source = source; - } - + // ---------------------------------------------------------------------------------- + // Other Methods + // ---------------------------------------------------------------------------------- public String getTitle() { return hasEntity() ? getEntityTitle() : "[Deleted entity]"; } - public User getCausedBy() { - return causedBy; - } - - public void setCausedBy(User user) { - this.causedBy = user; - } - /** * Override this method if the event has an association with a {@link Project}. * @@ -154,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; - } } -- 2.39.5 From 081678fcacd9719e3bfee1c28d33fdb5b8386a12 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 6 Nov 2024 11:52:59 +0100 Subject: [PATCH 78/99] task/3382: Add back unique key to table idea and fix 'on delete set null' to peer_request and activity_template --- .../db/migration/V390__harmonize_table_attribute_name.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 77136f8df6..ef809dd844 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -1040,7 +1040,7 @@ alter table `activity_template` rename column `checkListTemplate_id` to `checkli alter table `activity_template` add constraint fk_activity_template_checklist_template_id foreign key (checklist_template_id) references checklist_template (id) - on delete cascade on update cascade; + on delete set null on update cascade; -- table: ActivityPlanTemplate (at this stage, no any foreign key is referenced to ActivityPlanTemplate) @@ -1648,6 +1648,8 @@ alter table `idea` change `interests` `interests` longtext default null after `m 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) @@ -1932,7 +1934,7 @@ alter table `peer_request` change `file_reference_id` `file_reference_id` bigint alter table `peer_request` add constraint fk_peer_request_checklist_template_id foreign key (checklist_template_id) references checklist_template (id) - on delete cascade on update cascade; + on delete set null on update cascade; alter table `peer_request` add constraint fk_peer_request_file_reference_id -- 2.39.5 From 0c93ee2f6b1a6026da8daf05e81e2039c54cd926 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 6 Nov 2024 12:04:14 +0100 Subject: [PATCH 79/99] task/3382: Use _sv and _en consistently on publication_metadata and national_subject_category --- .../se/su/dsv/scipro/grading/NationalSubjectCategory.java | 4 ++-- .../se/su/dsv/scipro/grading/PublicationMetadata.java | 8 ++++---- .../db/migration/V390__harmonize_table_attribute_name.sql | 7 +++++++ 3 files changed, 13 insertions(+), 6 deletions(-) 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 1aa51eca5c..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 @@ -21,11 +21,11 @@ public class NationalSubjectCategory { private Long id; @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 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 1a5028425d..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 @@ -25,19 +25,19 @@ public class PublicationMetadata { private Long id; @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; // ---------------------------------------------------------------------------------- diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index ef809dd844..03bd459f50 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -2460,6 +2460,8 @@ alter table `grading_history_approval` 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` @@ -2475,6 +2477,11 @@ alter table `publication_metadata` drop key `FK_publication_metadata_national_su 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) -- 2.39.5 From 4fde7fdac9ad1f2e80de402c653be43bccbaa49b Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Wed, 6 Nov 2024 12:16:50 +0100 Subject: [PATCH 80/99] task/3382: Update enum NOT_APPLICABLE due to typo --- .../dsv/scipro/checklist/ChecklistAnswer.java | 77 ++++++++++++------- .../V390__harmonize_table_attribute_name.sql | 3 + 2 files changed, 53 insertions(+), 27 deletions(-) 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 28e61ce945..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 @@ -2,6 +2,7 @@ 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; @@ -20,22 +21,34 @@ import se.su.dsv.scipro.system.User; @Entity @Table(name = "checklist_answer") public class ChecklistAnswer extends DomainObject { + // ---------------------------------------------------------------------------------- + // Basic JPA-mappings + // ---------------------------------------------------------------------------------- @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Enumerated(EnumType.STRING) + @Basic @Column(name = "answer", nullable = false) + @Enumerated(EnumType.STRING) private ChecklistAnswerEnum answer; - @ManyToOne(optional = false) - @JoinColumn(name = "user_id") - 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() { } @@ -48,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; @@ -95,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/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 03bd459f50..b6cbe5a000 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -1363,6 +1363,9 @@ alter table `checklist_answer` 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'; + -- table: checklist_question alter table `checklist_question` rename column `questionNumber` to `question_number`; -- 2.39.5 From cfd42bcaf5576c6fa68e4b2de092a133e1a08af0 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 7 Nov 2024 09:48:19 +0100 Subject: [PATCH 81/99] task/3382: Fix a few SQL errors, and ajusted JPA-mappings --- .../dsv/scipro/finalthesis/FinalThesis.java | 8 +-- .../dsv/scipro/report/GradingCriterion.java | 4 +- .../V390__harmonize_table_attribute_name.sql | 59 ++----------------- 3 files changed, 12 insertions(+), 59 deletions(-) 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 c238089a33..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 @@ -36,12 +36,12 @@ public class FinalThesis extends DomainObject { private Long id; @Basic - @Column(name = "english_title") - private String englishTitle; + @Column(name = "title_sv") + private String swedishTitle; @Basic - @Column(name = "swedish_title") - private String swedishTitle; + @Column(name = "title_en") + private String englishTitle; @Basic @Column(name = "status") 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 5c7ab98ca4..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 @@ -18,9 +18,9 @@ import java.util.List; import java.util.Objects; @Entity -@DiscriminatorColumn(name = "type") -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @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; diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index b6cbe5a000..b17571b149 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -1535,7 +1535,7 @@ alter table `idea_keyword` -- table: keyword -alter table `keyword` drop key `deleted_index`; +alter table `Keyword` drop key `deleted_index`; rename table `Keyword` to `keyword`; @@ -1635,6 +1635,8 @@ 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`; @@ -2321,11 +2323,6 @@ alter table `GradingCriterion` change `gradingReport_id` `grading_report_id` big rename table `GradingCriterion` to `grading_criterion`; -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; - -- add foreign key reference from grading_criterion_point to grading_criterion alter table `grading_criterion_point` @@ -2690,9 +2687,9 @@ alter table FinalThesis drop key `FK_final_thesis_project`; rename table FinalThesis to `final_thesis`; -alter table `final_thesis` change `englishTitle` `english_title` varchar(255) default null after `version`; -alter table `final_thesis` change `swedishTitle` `swedish_title` varchar(255) default null after `english_title`; -alter table `final_thesis` change `status` `status` varchar(32) not null after `swedish_title`; +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`; @@ -3230,47 +3227,3 @@ 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; - --- todo: NotificationEvent, JPA-mapping - -/* Useful SQL - ->>> SQL query for FK-to: - -select table_name, column_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage - where table_schema = 'tozh4728' and referenced_table_name = 'ProjectType'; - ->>> SQL query for FK-to count: - - select referenced_table_name, count(*) as c - from information_schema.key_column_usage - where table_schema = 'tozh4728' and referenced_table_name is not null - group by referenced_table_name order by c desc; - ->>> SQL Query for FK-from - - select table_name, column_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage - where referenced_table_name is not null and table_name = 'user' -order by table_name; - ->>> Show foreign keys - - -- show foreign keys for a simple table - select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage - where table_schema = 'tozh4728' and - table_name = 'grade' and - constraint_name != 'PRIMARY'; - - -- show foreign keys for all tables - select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name - from information_schema.key_column_usage - where table_schema = 'tozh4728' and - constraint_name != 'PRIMARY' - order by table_name collate utf8_nopad_bin, constraint_name collate utf8_nopad_bin; - ->>> Show collation; - -*/ \ No newline at end of file -- 2.39.5 From f507fcf0ec02790c2c9448bda1ca9e86e5471023 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 7 Nov 2024 12:42:05 +0100 Subject: [PATCH 82/99] task/3382: Use editor-fold to surround different sections of entity classes --- .../su/dsv/scipro/activityplan/Activity.java | 48 ++++++++----------- .../dsv/scipro/activityplan/ActivityPlan.java | 46 ++++++++---------- 2 files changed, 41 insertions(+), 53 deletions(-) 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 898c74ef76..0b7e049f1f 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 @@ -30,10 +30,13 @@ import java.util.Objects; @Table(name = "activity") @Cacheable(true) public class Activity extends LazyDeletableDomainObject { - // ---------------------------------------------------------------------------------- - // basic JPA-mappings - // ---------------------------------------------------------------------------------- - @Id + + public static IActivityPlan builder(){ + return new Builder(); + } + + // + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -56,10 +59,9 @@ public class Activity extends LazyDeletableDomainObject { @Enumerated(EnumType.STRING) @Column(name = "action") private Action action = Action.NONE; + // - // ---------------------------------------------------------------------------------- - // JPA-mappings of foreign keys in this table (activity) referencing other tables. - // ---------------------------------------------------------------------------------- + // @ManyToOne(optional = false) @JoinColumn(name = "activity_plan_id", referencedColumnName = "id") @QueryInit("project") @@ -70,20 +72,18 @@ public class Activity extends LazyDeletableDomainObject { private Checklist checklist; @OneToOne(optional = true, cascade = CascadeType.ALL) - @JoinColumn(name = "file_upload_reference_id", referencedColumnName = "id") + @JoinColumn(name = "file_reference_id", referencedColumnName = "id") private FileReference fileUpload; + // - // ---------------------------------------------------------------------------------- - // constructor - // ---------------------------------------------------------------------------------- + // public Activity() { this.title = ""; this.description = ""; } + // - // ---------------------------------------------------------------------------------- - // getters and setters - // ---------------------------------------------------------------------------------- + // @Override public Long getId() { return this.id; @@ -156,10 +156,9 @@ public class Activity extends LazyDeletableDomainObject { public void setFileUpload(FileReference fileUpload) { this.fileUpload = fileUpload; } + // - // ---------------------------------------------------------------------------------- - // other methods - // ---------------------------------------------------------------------------------- + // @Override public boolean equals(final Object o) { if (o == this) return true; @@ -178,21 +177,15 @@ public class Activity extends LazyDeletableDomainObject { public String toString(){ return "Event: "+ getTitle()+"@"+getDate(); } + // + // protected boolean canEqual(final Object other) { return other instanceof Activity; } + // - // ---------------------------------------------------------------------------------- - // static methods - // ---------------------------------------------------------------------------------- - public static IActivityPlan builder(){ - return new Builder(); - } - - // ---------------------------------------------------------------------------------- - // nested classes - // ---------------------------------------------------------------------------------- + // public static class ByDateComparator implements Comparator, Serializable { @Override public int compare(Activity o1, Activity o2) { @@ -269,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 79cc1b599a..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 @@ -22,12 +22,15 @@ import java.util.Set; import java.util.TreeSet; @Entity -@Table(name =" activity_plan") +@Table(name ="activity_plan") @Cacheable(true) public class ActivityPlan extends DomainObject { - // ---------------------------------------------------------------------------------- - // basic JPA-mappings - // ---------------------------------------------------------------------------------- + + public static IProject builder() { + return new Builder(); + } + + // @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -35,23 +38,20 @@ public class ActivityPlan extends DomainObject { @Basic @Column(name = "start_date") private Date startDate; + // - // ---------------------------------------------------------------------------------- - // JPA-mappings of foreign keys in this table (activity_plan) referencing other tables. - // ---------------------------------------------------------------------------------- + // @OneToOne(optional=false) @JoinColumn(name = "project_id", referencedColumnName = "id") private Project project; + // - // ---------------------------------------------------------------------------------- - // JPA-mappings of other tables referencing to this table "activity_plan" - // ---------------------------------------------------------------------------------- + // @OneToMany(mappedBy= "activityPlan",cascade=CascadeType.PERSIST, orphanRemoval = true) private Set activities = new TreeSet<>(new Activity.ByDateComparator()); + // - // ---------------------------------------------------------------------------------- - // getters and setters - // ---------------------------------------------------------------------------------- + // @Override public Long getId() { return this.id; @@ -84,10 +84,9 @@ public class ActivityPlan extends DomainObject { public void setActivities(Set activities) { this.activities = activities; } + // - // ---------------------------------------------------------------------------------- - // other methods - // ---------------------------------------------------------------------------------- + // @Override public boolean equals(final Object o) { if (o == this) return true; @@ -110,21 +109,15 @@ public class ActivityPlan extends DomainObject { return "ActivityPlan(id=" + this.getId() + ", activities=" + this.getActivities() + ", project=" + this.getProject() + ", startDate=" + this.getStartDate() + ")"; } + // + // protected boolean canEqual(final Object other) { return other instanceof ActivityPlan; } + // - // ---------------------------------------------------------------------------------- - // static methods - // ---------------------------------------------------------------------------------- - public static IProject builder() { - return new Builder(); - } - - // ---------------------------------------------------------------------------------- - // nested classes - // ---------------------------------------------------------------------------------- + // } -- 2.39.5 From 0b02eb537ed8f9ac62d682823560a12e4daf32ff Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 7 Nov 2024 15:44:09 +0100 Subject: [PATCH 83/99] task/3382: Since one of ChecklistAnswerEnum values is changed to NOT_APPLICABLE, Wicket properties files need to change as well --- .../scipro/checklists/ChecklistOverviewPanel.utf8.properties | 2 +- .../java/se/su/dsv/scipro/peer/DisplayQuestionPanel.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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 -- 2.39.5 From f478521502bce44a549a22e1269be21e278d8f6d Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 7 Nov 2024 15:52:55 +0100 Subject: [PATCH 84/99] task/3382: Correct typo, to grading_report_template --- .../java/se/su/dsv/scipro/report/GradingReportTemplate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0a6afd4394..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 @@ -59,7 +59,7 @@ public class GradingReportTemplate extends DomainObject { private ProjectType projectType; // ---------------------------------------------------------------------------------- - // JPA-mappings of other tables referencing to this table "grading_report_tempalte" + // 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<>(); -- 2.39.5 From 8b705706b5088990a780d509d8ebfc77854a0ada Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Thu, 7 Nov 2024 15:53:52 +0100 Subject: [PATCH 85/99] task/3382: Add editor-folding support to ActivityPlanTemplate and ActivityTemplate --- .../activityplan/ActivityPlanTemplate.java | 74 ++++++----- .../scipro/activityplan/ActivityTemplate.java | 118 +++++++++++------- 2 files changed, 117 insertions(+), 75 deletions(-) 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 ff0bf1be27..6de9fe5815 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 @@ -6,6 +6,7 @@ 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; @@ -28,28 +29,38 @@ import se.su.dsv.scipro.system.User; @Cacheable(true) public class ActivityPlanTemplate extends DomainObject { + // @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Basic @Column(name = "is_sys_admin_template", nullable=false) private boolean isSysAdminTemplate = false; + @Basic @Column(nullable=false) private String title; + @Basic + @Column(name = "description") @Lob private String description; + // - @OrderColumn(name = "number_in_order") - @OneToMany(mappedBy="activityPlanTemplate", orphanRemoval=true, cascade=CascadeType.ALL) - private List activityTemplates = new ArrayList<>(); - - @ManyToOne(optional=false) + // + @ManyToOne(optional=false) @JoinColumn(name = "user_id") private User creator; + // + // + @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; @@ -83,28 +94,6 @@ public class ActivityPlanTemplate extends DomainObject { this.description = description; } - 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); - } - - public List getActivityTemplates(){ - return Collections.unmodifiableList(activityTemplates); - } - - public void setActivityTemplates(List activityTemplates){ - this.activityTemplates = new ArrayList<>(activityTemplates); - } - public User getCreator() { return this.creator; } @@ -113,6 +102,16 @@ public class ActivityPlanTemplate extends DomainObject { 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; @@ -139,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 2b24253c8b..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 @@ -2,6 +2,7 @@ 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; @@ -21,110 +22,121 @@ import se.su.dsv.scipro.system.DomainObject; @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 - @JoinColumn(name = "activity_plan_template_id") - private ActivityPlanTemplate activityPlanTemplate; - + @Basic @Column(name = "days_offset", nullable = false) private int daysOffset; + @Basic + @Column(name = "action") @Enumerated(EnumType.STRING) private Action action = Action.NONE; - @Column(name =" number_in_order", 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") + @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; @@ -134,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; + } + // +} -- 2.39.5 From 75cc952d48569df97354f68dc4aef757bf1ce69b Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 11 Nov 2024 10:08:51 +0100 Subject: [PATCH 86/99] task/3382: Add missing column name to dateCreated for IdeaParticipation --- .../main/java/se/su/dsv/scipro/match/IdeaParticipation.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 e0ee0aeeb6..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,8 +1,7 @@ package se.su.dsv.scipro.match; -import jakarta.persistence.AssociationOverride; -import jakarta.persistence.AssociationOverrides; import jakarta.persistence.Basic; +import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -10,7 +9,6 @@ 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; @@ -30,6 +28,7 @@ public class IdeaParticipation implements Serializable { private Long id; @Basic + @Column(name = "date_created") private Date dateCreated = new Date(); // ---------------------------------------------------------------------------------- -- 2.39.5 From 004b68b98de2c7400dbfc442b0b7c708434f539f Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 11 Nov 2024 10:20:16 +0100 Subject: [PATCH 87/99] task/3382: Update table answer with enum value NOT_APPLICABLE as well --- .../db/migration/V390__harmonize_table_attribute_name.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index b17571b149..7911d7496f 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -1365,6 +1365,7 @@ alter table `checklist_answer` -- 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 -- 2.39.5 From a5b2bb614be77798122bce74f758b6bb627a56db Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 11 Nov 2024 11:03:14 +0100 Subject: [PATCH 88/99] task/3382: Add JPA-annotations to all children classes to NotificationEvent (missed these earlier) --- .../notifications/dataobject/CustomEvent.java | 4 + .../notifications/dataobject/GroupEvent.java | 44 +++++---- .../notifications/dataobject/IdeaEvent.java | 41 ++++---- .../dataobject/MileStoneEvent.java | 98 ++++++++++--------- .../notifications/dataobject/PeerEvent.java | 35 ++++--- .../dataobject/PeerRequestEvent.java | 6 ++ .../dataobject/ProjectEvent.java | 54 +++++----- .../dataobject/ProjectForumEvent.java | 34 ++++--- .../dataobject/SeminarEvent.java | 35 ++++--- 9 files changed, 202 insertions(+), 149 deletions(-) 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..595b2c88fd 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,36 @@ import jakarta.persistence.ManyToOne; @Entity public class GroupEvent extends NotificationEvent { - public void setEvent(Event event) { - this.event = event; + @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); } - public enum Event { - MESSAGE_THREAD_CREATED, MESSAGE_THREAD_REPLY + @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(); @@ -56,4 +58,8 @@ public class GroupEvent extends NotificationEvent { public DomainObject getEntity() { return group; } + + public enum Event { + MESSAGE_THREAD_CREATED, MESSAGE_THREAD_REPLY + } } 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..505da3d7ba 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,24 @@ 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 +44,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(); @@ -58,4 +58,9 @@ public class IdeaEvent extends NotificationEvent { public DomainObject getEntity() { return idea; } + + public enum Event { + STATUS_CHANGE, PARTNER_ACCEPT, + ADDED_AS_PARTNER, FIRST_MEETING, REMOVED_AS_PARTNER, EXPORTED_FAIL + } } 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..732482b188 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; @@ -13,28 +16,64 @@ import java.util.Objects; @Entity public class MileStoneEvent extends NotificationEvent { - public enum Event { - 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 @@ -52,40 +91,7 @@ public class MileStoneEvent extends NotificationEvent { 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()); + public enum Event { + MILESTONE_CONFIRMED, MILESTONE_REVOKED } } 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..d290f4611b 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,26 @@ 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; - + @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 +46,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 @@ -61,4 +64,8 @@ public class PeerEvent extends NotificationEvent { public DomainObject getEntity() { return review; } + + public enum Event { + REVIEW_COMPLETED, REVIEW_COMMENT, REVIEW_ACCEPTED, REQUEST_DELETED, + REQUEST_EXPIRED } } 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..bc0b4ecc88 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; @@ -11,37 +14,19 @@ import jakarta.persistence.ManyToOne; @Entity public class ProjectEvent extends NotificationEvent { - public enum Event { - CREATED, AUTHORS_CHANGED, HEAD_SUPERVISOR_CHANGED, REVIEWERS_CHANGED, CO_SUPERVISOR_CHANGED, - STATE_CHANGED, ACTIVITY_ADDED, ACTIVITY_REMOVED, ACTIVITY_EDITED, FILE_UPLOADED, CHECKLIST_ANSWERED, - CHECKLIST_ADDED, MILESTONE_CONFIRMED, MILESTONE_REVOKED, FINAL_THESIS_APPROVED, FILE_SIZE_TOO_BIG, - FINAL_THESIS_UPLOADED, PROJECT_ACTIVATED, PROJECT_DEACTIVATED, FINAL_SEMINAR_APPROVAL_REQUESTED, - 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 - } - - @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 +36,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(); @@ -65,4 +59,16 @@ public class ProjectEvent extends NotificationEvent { public DomainObject getEntity() { return project; } + + public enum Event { + CREATED, AUTHORS_CHANGED, HEAD_SUPERVISOR_CHANGED, REVIEWERS_CHANGED, CO_SUPERVISOR_CHANGED, + STATE_CHANGED, ACTIVITY_ADDED, ACTIVITY_REMOVED, ACTIVITY_EDITED, FILE_UPLOADED, CHECKLIST_ANSWERED, + CHECKLIST_ADDED, MILESTONE_CONFIRMED, MILESTONE_REVOKED, FINAL_THESIS_APPROVED, FILE_SIZE_TOO_BIG, + FINAL_THESIS_UPLOADED, PROJECT_ACTIVATED, PROJECT_DEACTIVATED, FINAL_SEMINAR_APPROVAL_REQUESTED, + 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 + } } 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..c4ca9fb4f4 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,20 @@ import jakarta.persistence.ManyToOne; @Entity public class ProjectForumEvent extends NotificationEvent { - @ManyToOne - private Project project; + @Basic + @Column(name = "event") @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 - } + @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 +36,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(); @@ -57,4 +60,7 @@ public class ProjectForumEvent extends NotificationEvent { return project; } + public enum Event { + NEW_FORUM_POST, NEW_FORUM_POST_COMMENT, NEW_REVIEWER_INTERACTION + } } 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..5f71fc87a3 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,19 @@ 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; - + @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 +37,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(); @@ -61,4 +64,8 @@ public class SeminarEvent extends NotificationEvent { public DomainObject getEntity() { return 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} } -- 2.39.5 From 353ead7966baa8619db51e7e976aec839e6d0b5b Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Mon, 11 Nov 2024 11:11:58 +0100 Subject: [PATCH 89/99] task/3382: Move back public nested types Event to top of the class definition to improved readability. --- .../notifications/dataobject/GroupEvent.java | 8 +++---- .../notifications/dataobject/IdeaEvent.java | 10 ++++---- .../dataobject/MileStoneEvent.java | 8 +++---- .../notifications/dataobject/PeerEvent.java | 9 +++---- .../dataobject/ProjectEvent.java | 24 +++++++++---------- .../dataobject/ProjectForumEvent.java | 8 +++---- .../dataobject/SeminarEvent.java | 9 +++---- 7 files changed, 39 insertions(+), 37 deletions(-) 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 595b2c88fd..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 @@ -14,6 +14,10 @@ import jakarta.persistence.ManyToOne; @Entity public class GroupEvent extends NotificationEvent { + public enum Event { + MESSAGE_THREAD_CREATED, MESSAGE_THREAD_REPLY + } + @Basic @Column(name = "event") @Enumerated(EnumType.STRING) @@ -58,8 +62,4 @@ public class GroupEvent extends NotificationEvent { public DomainObject getEntity() { return group; } - - public enum Event { - MESSAGE_THREAD_CREATED, MESSAGE_THREAD_REPLY - } } 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 505da3d7ba..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 @@ -14,6 +14,11 @@ 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 + } + @Basic @Column(name = "event") @Enumerated(EnumType.STRING) @@ -58,9 +63,4 @@ public class IdeaEvent extends NotificationEvent { public DomainObject getEntity() { return idea; } - - public enum Event { - STATUS_CHANGE, PARTNER_ACCEPT, - ADDED_AS_PARTNER, FIRST_MEETING, REMOVED_AS_PARTNER, EXPORTED_FAIL - } } 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 732482b188..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 @@ -16,6 +16,10 @@ import java.util.Objects; @Entity public class MileStoneEvent extends NotificationEvent { + public enum Event { + MILESTONE_CONFIRMED, MILESTONE_REVOKED + } + @Basic @Column(name = "event") @Enumerated(EnumType.STRING) @@ -90,8 +94,4 @@ public class MileStoneEvent extends NotificationEvent { public DomainObject getEntity() { return milestone; } - - public enum Event { - MILESTONE_CONFIRMED, MILESTONE_REVOKED - } } 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 d290f4611b..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 @@ -15,6 +15,11 @@ import jakarta.persistence.ManyToOne; @Entity public class PeerEvent extends NotificationEvent { + public enum Event { + REVIEW_COMPLETED, REVIEW_COMMENT, REVIEW_ACCEPTED, REQUEST_DELETED, + REQUEST_EXPIRED + } + @Basic @Column(name = "event") @Enumerated(EnumType.STRING) @@ -64,8 +69,4 @@ public class PeerEvent extends NotificationEvent { public DomainObject getEntity() { return review; } - - public enum Event { - REVIEW_COMPLETED, REVIEW_COMMENT, REVIEW_ACCEPTED, REQUEST_DELETED, - REQUEST_EXPIRED } } 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 bc0b4ecc88..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 @@ -14,6 +14,18 @@ import jakarta.persistence.ManyToOne; @Entity public class ProjectEvent extends NotificationEvent { + public enum Event { + CREATED, AUTHORS_CHANGED, HEAD_SUPERVISOR_CHANGED, REVIEWERS_CHANGED, CO_SUPERVISOR_CHANGED, + STATE_CHANGED, ACTIVITY_ADDED, ACTIVITY_REMOVED, ACTIVITY_EDITED, FILE_UPLOADED, CHECKLIST_ANSWERED, + CHECKLIST_ADDED, MILESTONE_CONFIRMED, MILESTONE_REVOKED, FINAL_THESIS_APPROVED, FILE_SIZE_TOO_BIG, + FINAL_THESIS_UPLOADED, PROJECT_ACTIVATED, PROJECT_DEACTIVATED, FINAL_SEMINAR_APPROVAL_REQUESTED, + 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 + } + @Basic @Column(name = "event") @Enumerated(EnumType.STRING) @@ -59,16 +71,4 @@ public class ProjectEvent extends NotificationEvent { public DomainObject getEntity() { return project; } - - public enum Event { - CREATED, AUTHORS_CHANGED, HEAD_SUPERVISOR_CHANGED, REVIEWERS_CHANGED, CO_SUPERVISOR_CHANGED, - STATE_CHANGED, ACTIVITY_ADDED, ACTIVITY_REMOVED, ACTIVITY_EDITED, FILE_UPLOADED, CHECKLIST_ANSWERED, - CHECKLIST_ADDED, MILESTONE_CONFIRMED, MILESTONE_REVOKED, FINAL_THESIS_APPROVED, FILE_SIZE_TOO_BIG, - FINAL_THESIS_UPLOADED, PROJECT_ACTIVATED, PROJECT_DEACTIVATED, FINAL_SEMINAR_APPROVAL_REQUESTED, - 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 - } } 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 c4ca9fb4f4..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 @@ -14,6 +14,10 @@ import jakarta.persistence.ManyToOne; @Entity public class ProjectForumEvent extends NotificationEvent { + public enum Event { + NEW_FORUM_POST, NEW_FORUM_POST_COMMENT, NEW_REVIEWER_INTERACTION + } + @Basic @Column(name = "event") @Enumerated(EnumType.STRING) @@ -59,8 +63,4 @@ public class ProjectForumEvent extends NotificationEvent { public DomainObject getEntity() { return project; } - - public enum Event { - NEW_FORUM_POST, NEW_FORUM_POST_COMMENT, NEW_REVIEWER_INTERACTION - } } 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 5f71fc87a3..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 @@ -15,6 +15,11 @@ 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 + } + @Basic @Column(name = "event") @Enumerated(EnumType.STRING) @@ -64,8 +69,4 @@ public class SeminarEvent extends NotificationEvent { public DomainObject getEntity() { return 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} } -- 2.39.5 From f11fdcfb984a71c0778a19c683f7cc6d8f448fe0 Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Mon, 11 Nov 2024 15:44:11 +0100 Subject: [PATCH 90/99] Fix foreign key names The names in production are somehow different from what the migrations say they should be. The production database has been manually corrected to match the names in the migration scripts. --- .../V390__harmonize_table_attribute_name.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 7911d7496f..ad61842df7 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -909,7 +909,7 @@ alter table `checklist_template_project_type` -- table: milestone_activity_template_ProjectType, except foreign key to coming table project_type -alter table `milestone_activity_template_ProjectType` drop foreign key `milestone_activity_template_ProjectType_ibfk_1`; +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`; @@ -1823,7 +1823,7 @@ alter table `activity_thread` -- table: project_first_meeting, except foreign key to becoming table activity -alter table `project_first_meeting` drop foreign key `project_first_meeting_ibfk_1`; +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`; @@ -2715,7 +2715,7 @@ alter table `final_thesis` -- table: project_file -alter table `project_file` drop foreign key project_file_ibfk_2; +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; @@ -2805,7 +2805,7 @@ alter table `decision` -- table: urkund_submission -alter table `urkund_submission` drop foreign key `urkund_submission_ibfk_2`; +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`; @@ -2831,7 +2831,7 @@ alter table `urkund_submission` -- table: plagiarism_request -alter table `plagiarism_request` drop foreign key `plagiarism_request_ibfk_2`; +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`; @@ -3151,7 +3151,7 @@ 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_sqjaj3jb6t9lsw1l2p8ex8jnb`; +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`; -- 2.39.5 From df29afdacc0ebfb1e98c0b4180ec9e08974a229a Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 09:47:00 +0100 Subject: [PATCH 91/99] task/3382: Rename 'user_name' to 'username' --- .../java/se/su/dsv/scipro/system/Username.java | 15 ++++++++++++--- .../V390__harmonize_table_attribute_name.sql | 10 +++------- 2 files changed, 15 insertions(+), 10 deletions(-) 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 9ea10e3f0c..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="user_name", uniqueConstraints={@UniqueConstraint(name = "uk_user_name", columnNames={"user_name"})}) public class Username extends DomainObject { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(name = "user_name", nullable = false) + @Column(name = "username", nullable = false) private String username; @ManyToOne(optional=false) diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index ad61842df7..6a97b3eba2 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -587,14 +587,10 @@ alter table `username` drop foreign key `FK_17moq4bksxe30ihucce3jovdc`; alter table `username` drop key `FK_17moq4bksxe30ihucce3jovdc`; alter table `username` drop key `username_must_be_unique`; -rename table `username` to `user_name`; +alter table `username` add constraint uk_username unique(username); -alter table `user_name` rename column `username` to `user_name`; - -alter table `user_name` add constraint uk_user_name unique(user_name); - -alter table `user_name` - add constraint fk_user_name_user_id +alter table `username` + add constraint fk_username_user_id foreign key (user_id) references user (id) on delete cascade on update cascade; -- 2.39.5 From 05e5725581976ed38e94337059c9bbb962b1c3da Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 09:55:53 +0100 Subject: [PATCH 92/99] task/3382: Rename 'user_name' to 'username' for urkund_settings --- .../su/dsv/scipro/plagiarism/urkund/UrkundSettings.java | 8 ++++++-- .../db/migration/V390__harmonize_table_attribute_name.sql | 4 ---- 2 files changed, 6 insertions(+), 6 deletions(-) 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 6301e08f80..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 @@ -17,12 +17,15 @@ public class UrkundSettings { private long id = ID; @Basic + @Column(name = "enabled") private boolean enabled = false; - @Column(name = "user_name") + @Basic + @Column(name = "username") private String username; @Basic + @Column(name = "password") private String password; public boolean isEnabled() { @@ -72,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/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 6a97b3eba2..789534a9f6 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -383,10 +383,6 @@ alter table `NonWorkDayPeriod` rename column `startDate` to `start_date`; rename table `NonWorkDayPeriod` to `non_work_day_period`; --- table: urkund_settings - -alter table `urkund_settings` rename column `username` to `user_name`; - -- table: reviewer_deadline_settings alter table `reviewer_deadline_settings` rename column `roughDraftApproval` to `rough_draft_approval`; -- 2.39.5 From ccdfe6d97921a82187e84679b329afe437b472db Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 10:14:19 +0100 Subject: [PATCH 93/99] task/3382: Rename 'user_id' to 'reviewer_user_id' for reviewer_target --- .../se/su/dsv/scipro/reviewing/ReviewerTarget.java | 13 +++++++++---- .../V390__harmonize_table_attribute_name.sql | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) 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 2620dea69d..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; @@ -19,22 +20,26 @@ public class ReviewerTarget extends DomainObject { @GeneratedValue(strategy = jakarta.persistence.GenerationType.IDENTITY) private Long id; - @ManyToOne(optional = false) - @JoinColumn(name = "user_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/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 789534a9f6..906ea5a9c0 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -555,13 +555,13 @@ alter table `comment` 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 `user_id`; +alter table `reviewer_target` rename column `reviewer_id` to `reviewer_user_id`; -alter table `reviewer_target` add constraint uk_reviewer_target_user_id_year unique(user_id, year); +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_user_id - foreign key (user_id) references user (id) + 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 -- 2.39.5 From c833426a69c09f5003292cd3a52d7e7c32099407 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 10:48:11 +0100 Subject: [PATCH 94/99] task/3382: Rename 'user_id' to 'creator_user_id' for comment --- .../java/se/su/dsv/scipro/peer/Comment.java | 18 +++++++++++++++--- .../V390__harmonize_table_attribute_name.sql | 6 +++--- 2 files changed, 18 insertions(+), 6 deletions(-) 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 d217298107..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,14 +26,16 @@ public class Comment extends DomainObject { private Long id; @ManyToOne(optional = false) - @JoinColumn(name = "user_id") + @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") + @JoinColumn(name = "comment_thread_id", referencedColumnName = "id") private CommentThread commentThread; protected Comment() { diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 906ea5a9c0..3306215d7c 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -538,11 +538,11 @@ 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 `user_id`; +alter table comment rename column `creator_id` to `creator_user_id`; alter table `comment` - add constraint fk_comment_user_id - foreign key (user_id) references user (id) + add constraint fk_comment_creator_user_id + foreign key (creator_user_id) references user (id) on delete cascade on update cascade; alter table `comment` -- 2.39.5 From 9a8604d76a7542e595e5a6b377b320e2b57513d2 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 11:00:51 +0100 Subject: [PATCH 95/99] task/3382: Rename 'user_id' to 'creator_user_id' for activity_plan_template --- .../se/su/dsv/scipro/activityplan/ActivityPlanTemplate.java | 6 +++--- .../db/migration/V390__harmonize_table_attribute_name.sql | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) 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 6de9fe5815..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 @@ -39,7 +39,7 @@ public class ActivityPlanTemplate extends DomainObject { private boolean isSysAdminTemplate = false; @Basic - @Column(nullable=false) + @Column(name = "title", nullable = false) private String title; @Basic @@ -49,8 +49,8 @@ public class ActivityPlanTemplate extends DomainObject { // // - @ManyToOne(optional=false) - @JoinColumn(name = "user_id") + @ManyToOne(optional = false) + @JoinColumn(name = "creator_user_id", referencedColumnName = "id") private User creator; // diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 3306215d7c..57c3ea170c 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -1043,11 +1043,11 @@ 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 `user_id`; +alter table `activity_plan_template` rename column `creator_id` to `creator_user_id`; alter table `activity_plan_template` - add constraint fk_activity_plan_template_user_id - foreign key (user_id) references user (id) + 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 -- 2.39.5 From 0fb9e6dbc3749a5e4289b8b12a4fc112abb6bb79 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 11:14:41 +0100 Subject: [PATCH 96/99] task/3382: Rename 'user_id' to 'creator_user_id' for checklist_template --- .../scipro/checklist/ChecklistTemplate.java | 19 ++++++++++--------- .../V390__harmonize_table_attribute_name.sql | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) 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 da5381aa9c..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,5 @@ package se.su.dsv.scipro.checklist; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; - import jakarta.persistence.Basic; import jakarta.persistence.CollectionTable; import jakarta.persistence.Column; @@ -16,15 +10,19 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; -import jakarta.persistence.Lob; 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 java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; + @Entity @Table(name = "checklist_template") public class ChecklistTemplate extends DomainObject { @@ -35,12 +33,15 @@ 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; + @Basic @Column(name = "template_number") private int templateNumber = DEFAULT_TEMPLATE_NUMBER; @@ -51,7 +52,7 @@ public class ChecklistTemplate extends DomainObject { private List questions = new ArrayList<>(1); @ManyToOne(optional = false) - @JoinColumn(name = "user_id") + @JoinColumn(name = "creator_user_id", referencedColumnName = "id") private User creator; @ManyToMany diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 57c3ea170c..813dfeeb53 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -1402,12 +1402,12 @@ alter table `checklist_template_checklist_category` alter table `checklist_template` drop foreign key `FK14DA6F3E44F4DBE`; alter table `checklist_template` drop key `FK14DA6F3E44F4DBE`; -alter table `checklist_template` rename column `creator_id` to `user_id`; +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_user_id - foreign key (user_id) references user (id) + add constraint fk_checklist_template_creator_user_id + foreign key (creator_user_id) references user (id) on delete cascade on update cascade; /* -- 2.39.5 From 28e617ef9b250dd690db1ddaace6281699b2e4a4 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 11:27:33 +0100 Subject: [PATCH 97/99] task/3382: Rename 'file_reference_id' to 'upload_file_reference_id' for activity --- .../main/java/se/su/dsv/scipro/activityplan/Activity.java | 2 +- .../db/migration/V390__harmonize_table_attribute_name.sql | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 0b7e049f1f..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 @@ -72,7 +72,7 @@ public class Activity extends LazyDeletableDomainObject { private Checklist checklist; @OneToOne(optional = true, cascade = CascadeType.ALL) - @JoinColumn(name = "file_reference_id", referencedColumnName = "id") + @JoinColumn(name = "upload_file_reference_id", referencedColumnName = "id") private FileReference fileUpload; // diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index 813dfeeb53..ff485fe3b9 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -1841,7 +1841,7 @@ alter table `activity` change `action` `action` varchar(64) not null default 'no 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 `file_reference_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); @@ -1852,8 +1852,8 @@ alter table `activity` on delete cascade on update cascade ; alter table `activity` - add constraint `fk_activity_file_reference_id` - foreign key (file_reference_id) references file_reference (id) + 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 -- 2.39.5 From e36018f9273dd4a4a4b83323e3270f8dc774f000 Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 11:47:48 +0100 Subject: [PATCH 98/99] task/3382: Rename 'file_reference_id' to 'document_file_reference_id' for final_seminar --- .../java/se/su/dsv/scipro/finalseminar/FinalSeminar.java | 2 +- .../db/migration/V390__harmonize_table_attribute_name.sql | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 ab5fc08dbb..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 @@ -95,7 +95,7 @@ public class FinalSeminar extends LazyDeletableDomainObject { * to delete the document */ @OneToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "file_reference_id", referencedColumnName = "id") + @JoinColumn(name = "document_file_reference_id", referencedColumnName = "id") private FileReference document; @OneToOne(optional = false) diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql index ff485fe3b9..15c116c0ff 100644 --- a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql +++ b/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql @@ -2116,15 +2116,15 @@ alter table `final_seminar` change `creationReason` `creation_reason` mediumtext 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 `file_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_file_reference_id - foreign key (file_reference_id) references file_reference (id) + 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` -- 2.39.5 From 2f1e927ab7d52d9ca45894e4609c5a153b63865d Mon Sep 17 00:00:00 2001 From: Tom Zhao Date: Tue, 12 Nov 2024 11:53:22 +0100 Subject: [PATCH 99/99] task/3382: rename migration script version to V391 from V390 --- ...ttribute_name.sql => V391__harmonize_table_attribute_name.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/src/main/resources/db/migration/{V390__harmonize_table_attribute_name.sql => V391__harmonize_table_attribute_name.sql} (100%) diff --git a/core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql b/core/src/main/resources/db/migration/V391__harmonize_table_attribute_name.sql similarity index 100% rename from core/src/main/resources/db/migration/V390__harmonize_table_attribute_name.sql rename to core/src/main/resources/db/migration/V391__harmonize_table_attribute_name.sql -- 2.39.5