task/3382: Fixed project_group, project_group_project and their related JPA-mappings
This commit is contained in:
parent
9f13775096
commit
edd66e148b
core/src/main
@ -18,30 +18,124 @@ public class Group extends DomainObject {
|
|||||||
|
|
||||||
public static final int STRING_MAX_LENGTH = 255;
|
public static final int STRING_MAX_LENGTH = 255;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------
|
||||||
|
// Basic JPA-mappings
|
||||||
|
// ----------------------------------------------------------------------------------
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(length = STRING_MAX_LENGTH)
|
|
||||||
@Basic(optional = false)
|
@Basic(optional = false)
|
||||||
|
@Column(name = "title", length = STRING_MAX_LENGTH)
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@Basic(optional = true)
|
@Basic(optional = true)
|
||||||
|
@Column(name = "description")
|
||||||
private String 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
|
//Creator, should be a supervisor
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
@JoinColumn(name = "user_id")
|
@JoinColumn(name = "user_id", referencedColumnName = "id")
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------
|
||||||
|
// @ManyToMany JPA-mappings
|
||||||
|
// ----------------------------------------------------------------------------------
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(
|
@JoinTable(name = "project_group_project",
|
||||||
name = "project_group_project",
|
joinColumns = @JoinColumn(name = "project_group_id", referencedColumnName = "id"),
|
||||||
joinColumns = @JoinColumn(name = "project_group_id"),
|
inverseJoinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id"))
|
||||||
inverseJoinColumns = @JoinColumn(name = "project_id"))
|
|
||||||
private Set<Project> projects = new HashSet<>();
|
private Set<Project> 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<Project> getProjects() {
|
||||||
|
return projects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjects(Set<Project> 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) {
|
public boolean isAuthor(final User user) {
|
||||||
for (Project project : projects) {
|
for (Project project : projects) {
|
||||||
@ -58,76 +152,4 @@ public class Group extends DomainObject {
|
|||||||
.filter(member -> member.getType() != Member.Type.REVIEWER)
|
.filter(member -> member.getType() != Member.Type.REVIEWER)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public Set<Project> 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<Project> 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2887,6 +2887,48 @@ alter table `mail_event_non_user_recipient`
|
|||||||
foreign key (mail_event_id) references mail_event (id)
|
foreign key (mail_event_id) references mail_event (id)
|
||||||
on delete cascade on update cascade;
|
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
|
/* Useful SQL
|
||||||
|
|
||||||
>>> SQL query for FK-to:
|
>>> SQL query for FK-to:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user