task/3382: Harmonisera tabellnamn #6

Merged
ansv7779 merged 104 commits from task/3382 into develop 2024-11-12 13:33:44 +01:00
4 changed files with 291 additions and 55 deletions
Showing only changes of commit 2c775e9e70 - Show all commits

View File

@ -1,26 +1,44 @@
package se.su.dsv.scipro.forum.notifications; 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.forum.dataobjects.ForumPost;
import se.su.dsv.scipro.notifications.dataobject.NotificationEvent; import se.su.dsv.scipro.notifications.dataobject.NotificationEvent;
import jakarta.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
@Table(name = "forum_notification") @Table(name = "forum_notification")
class ForumNotification { class ForumNotification {
// ----------------------------------------------------------------------------------
// Embedded JPA-mapping
// ----------------------------------------------------------------------------------
@EmbeddedId @EmbeddedId
private Id id = new Id(); private Id id = new Id();
// ----------------------------------------------------------------------------------
// JPA-mappings of foreign keys in this table (forum_notification) referencing other
// tables.
// ----------------------------------------------------------------------------------
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "forum_post_id", referencedColumnName = "id")
@MapsId("forumPostId") @MapsId("forumPostId")
private ForumPost forumPost; private ForumPost forumPost;
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "notification_data_id")
@MapsId("notificationEventId") @MapsId("notificationEventId")
private NotificationEvent notificationEvent; private NotificationEvent notificationEvent;
// ----------------------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------------------
protected ForumNotification() { } // JPA protected ForumNotification() { } // JPA
ForumNotification(final ForumPost forumPost, final NotificationEvent notificationEvent) { ForumNotification(final ForumPost forumPost, final NotificationEvent notificationEvent) {
@ -28,6 +46,9 @@ class ForumNotification {
this.notificationEvent = notificationEvent; this.notificationEvent = notificationEvent;
} }
// ----------------------------------------------------------------------------------
// Properties (Getters)
// ----------------------------------------------------------------------------------
public ForumPost getForumPost() { public ForumPost getForumPost() {
return forumPost; return forumPost;
} }
@ -36,6 +57,9 @@ class ForumNotification {
return notificationEvent; return notificationEvent;
} }
// ----------------------------------------------------------------------------------
// Methods Common To All Objects
// ----------------------------------------------------------------------------------
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (o == this) return true; if (o == this) return true;
@ -47,10 +71,6 @@ class ForumNotification {
&& Objects.equals(this.getNotificationEvent(), other.getNotificationEvent()); && Objects.equals(this.getNotificationEvent(), other.getNotificationEvent());
} }
protected boolean canEqual(final Object other) {
return other instanceof ForumNotification;
}
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(this.id, this.getForumPost(), this.getNotificationEvent()); return Objects.hash(this.id, this.getForumPost(), this.getNotificationEvent());
@ -58,9 +78,20 @@ class ForumNotification {
@Override @Override
public String toString() { 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 @Embeddable
static class Id implements Serializable { static class Id implements Serializable {
private Long forumPostId; private Long forumPostId;
@ -103,7 +134,8 @@ class ForumNotification {
@Override @Override
public String toString() { public String toString() {
return "ForumNotification.Id(forumPostId=" + this.getForumPostId() + ", notificationEventId=" + this.getNotificationEventId() + ")"; return "ForumNotification.Id(forumPostId=" + this.getForumPostId() + ", notificationEventId=" +
this.getNotificationEventId() + ")";
} }
} }
} }

View File

@ -1,41 +1,59 @@
package se.su.dsv.scipro.notifications.dataobject; 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.project.Project;
import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.DomainObject;
import se.su.dsv.scipro.system.User; import se.su.dsv.scipro.system.User;
import jakarta.persistence.*;
@Entity @Entity
@Table(name = "notification")
public class Notification extends DomainObject { public class Notification extends DomainObject {
// ----------------------------------------------------------------------------------
public enum Type { // Basic JPA-mappings
PROJECT, IDEA, FINAL_SEMINAR, PEER, MILESTONE, // ----------------------------------------------------------------------------------
GROUP, FORUM, CUSTOM
}
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
@Basic(optional = false) @Basic(optional = false)
private boolean unread = true; @Column(name = "mailed")
@Basic(optional = false)
private boolean mailed = false; 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) @ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "notificationData_id") @JoinColumn(name = "notification_data_id", referencedColumnName = "id")
private NotificationEvent notificationEvent; private NotificationEvent notificationEvent;
@ManyToOne @ManyToOne
@JoinColumn(name = "user_id", referencedColumnName = "id")
private User user; private User user;
// ----------------------------------------------------------------------------------
// Constructor
// ----------------------------------------------------------------------------------
public Notification() { public Notification() {
} }
// ----------------------------------------------------------------------------------
// Properties (Getters and Setters)
// ----------------------------------------------------------------------------------
@Override @Override
public Long getId() { public Long getId() {
return id; return id;
@ -45,6 +63,14 @@ public class Notification extends DomainObject {
this.id = id; this.id = id;
} }
public boolean isMailed() {
return mailed;
}
public void setMailed(boolean mailed) {
this.mailed = mailed;
}
public boolean isUnread() { public boolean isUnread() {
return unread; return unread;
} }
@ -69,14 +95,9 @@ public class Notification extends DomainObject {
this.user = user; this.user = user;
} }
public boolean isMailed() { // ----------------------------------------------------------------------------------
return mailed; // Other methods
} // ----------------------------------------------------------------------------------
public void setMailed(boolean mailed) {
this.mailed = mailed;
}
public String getTitle() { public String getTitle() {
return getNotificationEvent().getTitle(); return getNotificationEvent().getTitle();
} }
@ -108,4 +129,12 @@ public class Notification extends DomainObject {
public User getCausedBy() { public User getCausedBy() {
return getNotificationEvent().getCausedBy(); return getNotificationEvent().getCausedBy();
} }
// ----------------------------------------------------------------------------------
// Nested type
// ----------------------------------------------------------------------------------
public enum Type {
PROJECT, IDEA, FINAL_SEMINAR, PEER, MILESTONE,
GROUP, FORUM, CUSTOM
}
} }

View File

@ -1,40 +1,103 @@
package se.su.dsv.scipro.notifications.dataobject; 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.project.Project;
import se.su.dsv.scipro.system.DomainObject; import se.su.dsv.scipro.system.DomainObject;
import se.su.dsv.scipro.system.User; import se.su.dsv.scipro.system.User;
import jakarta.persistence.*;
import java.util.Collection; import java.util.Collection;
@Entity @Entity
@Table(name = "notification_data")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "NotificationData") @DiscriminatorColumn(name = "subclass")
public abstract class NotificationEvent extends DomainObject { public abstract class NotificationEvent extends DomainObject {
// ----------------------------------------------------------------------------------
// Basic JPA-mappings
// ----------------------------------------------------------------------------------
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
protected long id; protected long id;
@Basic
@Column(name = "type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
protected Notification.Type type; protected Notification.Type type;
@OneToMany(mappedBy = "notificationEvent", cascade = CascadeType.ALL, orphanRemoval = true)
private Collection<Notification> notifications;
@Basic(optional = true) @Basic(optional = true)
@Column(name = "source")
private String source; private String source;
@Basic(optional = true) @Basic(optional = true)
@Column(name = "additional_source")
private String additionalSource; private String additionalSource;
// ----------------------------------------------------------------------------------
// JPA-mappings of foreign keys in this table (notification_data) referencing other
// tables.
// ----------------------------------------------------------------------------------
@ManyToOne(optional = true) @ManyToOne(optional = true)
@JoinColumn(name = "caused_by_user_id", referencedColumnName = "id")
private User causedBy; private User causedBy;
// ----------------------------------------------------------------------------------
// JPA-mappings of other tables referencing to this table "notification_data"
// ----------------------------------------------------------------------------------
@OneToMany(mappedBy = "notificationEvent", cascade = CascadeType.ALL, orphanRemoval = true)
private Collection<Notification> 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 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. * The title of the entity this event is about.
* *
@ -50,30 +113,10 @@ public abstract class NotificationEvent extends DomainObject {
public abstract DomainObject getEntity(); 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<Notification> getNotifications() { public Collection<Notification> getNotifications() {
return notifications; return notifications;

View File

@ -3069,6 +3069,138 @@ alter table `project_group_thread`
foreign key (thread_id) references thread (id) foreign key (thread_id) references thread (id)
on delete cascade on update cascade; 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 /* Useful SQL