task/3382: Harmonisera tabellnamn #6

Merged
ansv7779 merged 104 commits from task/3382 into develop 2024-11-12 13:33:44 +01:00
7 changed files with 311 additions and 119 deletions
Showing only changes of commit 5a92cbbce9 - Show all commits

View File

@ -294,6 +294,7 @@ public class FinalSeminar extends LazyDeletableDomainObject {
", maxParticipants=" + this.getMaxParticipants() + ", creationReason=" +
this.getCreationReason() + ")";
}
// ----------------------------------------------------------------------------------
// Other Methods
// ----------------------------------------------------------------------------------

View File

@ -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<AbstractCriterion>, Serializable {
@Override
public int compare(AbstractCriterion o1, AbstractCriterion o2) {

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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<Criterion> 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<Criterion> 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<Criterion> 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();
}
}

View File

@ -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;
}
}

View File

@ -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;
*/