Skip to content

Commit

Permalink
Workspace Add News, Author fixed in Revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
commel committed Mar 8, 2024
1 parent 1333899 commit 6028ce7
Show file tree
Hide file tree
Showing 20 changed files with 657 additions and 113 deletions.
6 changes: 3 additions & 3 deletions doc/db2/01_schema/06_news.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create table if not exists news_categories(
id integer primary key default nextval('hibernate_sequence'),
name varchar(255) not null,
active bool default false,
weight integer default 0,

created timestamptz not null default CURRENT_TIMESTAMP,
updated timestamptz not null default CURRENT_TIMESTAMP,
Expand All @@ -25,9 +26,8 @@ create table if not exists news_revisions(

content varchar(16384),
content_lang varchar(12) not null default 'german',

category varchar(255),
category_lang varchar(12) not null default 'german'

news_category_id integer references news_categories(id)
);

create table if not exists news(
Expand Down
1 change: 1 addition & 0 deletions doc/db2/02_data/01_roles_taggroups_forums.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ insert into attachment_types (code, label, attachment_group_id, datatype) values
('flatpak', 'Flatpak', (select id from attachment_groups where code = 'repo'), 'url'),
('Snap', 'Snap', (select id from attachment_groups where code = 'repo'), 'url');

insert into news_categories(name, active, weight) values ('News', true, 70), ('Drückblick', true, 50), ('Kurznews', true, 30), ('Review', true, 20), ('Artikel', true, 10), ('In eigener Sache', true, 1);
4 changes: 2 additions & 2 deletions src/main/java/de/holarse/backend/db/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class Article extends Base {
)
private Set<Tag> tags = new HashSet<>();

@OneToMany(cascade = { CascadeType.ALL })
@JoinColumn(name="nodeid", insertable=false, nullable=false, updatable = false, referencedColumnName = "nodeid")
@OneToMany(cascade = { CascadeType.ALL }, targetEntity=NodeSlug.class)
@JoinColumn(name="nodeid", insertable=false, nullable=false, updatable = false, referencedColumnName = "nodeid")
private Set<NodeSlug> nodeSlugs = new HashSet<>();

public int getNodeId() {
Expand Down
47 changes: 2 additions & 45 deletions src/main/java/de/holarse/backend/db/ArticleRevision.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

@Table(name = "article_revisions")
@Entity
public class ArticleRevision extends TimestampedBase {
public class ArticleRevision extends RevisionedNode {

private static final long serialVersionUID = 1L;

@Column(name = "nodeid", nullable = false)
private Integer nodeId;
@Column(name = "revision", nullable = false)
private Integer revision;

@Column(length = 512)
private String title1;
@Column(length = 512)
Expand All @@ -29,32 +25,9 @@ public class ArticleRevision extends TimestampedBase {
@Column(length = 16384)
private String content;

@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name="update_userid", insertable=false, nullable=false, updatable = false, referencedColumnName = "id")
private User author;

@Column(length = 512)
private String teaser;

@Column(length = 255)
private String changelog;

public Integer getNodeId() {
return nodeId;
}

public void setNodeId(Integer nodeId) {
this.nodeId = nodeId;
}

public Integer getRevision() {
return revision;
}

public void setRevision(Integer revision) {
this.revision = revision;
}

public String getTitle1() {
return title1;
}
Expand Down Expand Up @@ -119,27 +92,11 @@ public void setContent(String content) {
this.content = content;
}

public String getChangelog() {
return changelog;
}

public void setChangelog(String changelog) {
this.changelog = changelog;
}

public String getTeaser() {
return teaser;
}

public void setTeaser(String teaser) {
this.teaser = teaser;
}

public User getAuthor() {
return author;
}

public void setAuthor(User author) {
this.author = author;
}
}
107 changes: 107 additions & 0 deletions src/main/java/de/holarse/backend/db/News.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package de.holarse.backend.db;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
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 java.util.HashSet;
import java.util.Set;

@Table(name = "news")
@Entity
public class News extends Base {

private static final long serialVersionUID = 2L;

@Column(name = "nodeid")
private int nodeId;

@OneToOne
@JoinColumn(name = "revisionid", referencedColumnName = "id")
private NewsRevision newsRevision;

@Column(name = "drupalid")
private Integer drupalId;

@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name="nodeid", insertable=false, nullable=false, updatable = false, referencedColumnName = "nodeid")
private NodeStatus nodeStatus;

@ManyToMany(cascade = { CascadeType.ALL })
@JoinTable(
name = "node_tags",
joinColumns = { @JoinColumn(name = "nodeid", insertable=false, nullable=false, updatable = false, referencedColumnName = "nodeid") },
inverseJoinColumns = { @JoinColumn(name = "tagid") }
)
private Set<Tag> tags = new HashSet<>();

@OneToMany(cascade = { CascadeType.ALL })
@JoinColumn(name="nodeid", referencedColumnName = "nodeid")
private Set<NodeSlug> slugs = new HashSet<>(); // Muss nodeSlugz heissen, weil nodeSlugs in Article referenziert ist. Siehe Bug https://lists.jboss.org/pipermail/hibernate-issues/2011-January/027658.html

public int getNodeId() {
return nodeId;
}

public void setNodeId(int nodeId) {
this.nodeId = nodeId;
}

public Integer getDrupalId() {
return drupalId;
}

public void setDrupalId(Integer drupalId) {
this.drupalId = drupalId;
}

public NewsRevision getNewsRevision() {
return newsRevision;
}

public void setNewsRevision(NewsRevision articleRevision) {
this.newsRevision = newsRevision;
}

public NodeStatus getNodeStatus() {
return nodeStatus;
}

public void setNodeStatus(NodeStatus nodeStatus) {
this.nodeStatus = nodeStatus;
}

public Set<Tag> getTags() {
return tags;
}

public void setTags(Set<Tag> tags) {
this.tags = tags;
}

public Set<NodeSlug> getSlugs() {
return slugs;
}

public void setSlugs(Set<NodeSlug> slugs) {
this.slugs = slugs;
}

@Override
public String toString() {
return "News{" +
"nodeId=" + nodeId +
", newsRevision=" + newsRevision +
", drupalId=" + drupalId +
", nodeStatus=" + nodeStatus +
", tags=" + tags +
", slugs=" + slugs +
'}';
}
}
42 changes: 42 additions & 0 deletions src/main/java/de/holarse/backend/db/NewsCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.holarse.backend.db;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

@Table(name = "news_categories")
@Entity
public class NewsCategory extends Base {

@Column(length = 255)
private String name;

@Column(name="active", columnDefinition = "boolean default false")
private boolean active;

private int weight;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}

public int getWeight() {
return weight;
}

public void setWeight(int weight) {
this.weight = weight;
}
}
52 changes: 52 additions & 0 deletions src/main/java/de/holarse/backend/db/NewsRevision.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.holarse.backend.db;

import jakarta.persistence.*;

@Table(name = "news_revisions")
@Entity
public class NewsRevision extends RevisionedNode {

private static final long serialVersionUID = 1L;

@Column(length = 255)
private String title;
@Column(length = 16384)
private String content;

@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumn(name="news_category_id", referencedColumnName = "id")
private NewsCategory newsCategory;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public NewsCategory getNewsCategory() {
return newsCategory;
}

public void setNewsCategory(NewsCategory newsCategory) {
this.newsCategory = newsCategory;
}

@Override
public String toString() {
return "NewsRevision{" +
"title='" + title + '\'' +
", content='" + content + '\'' +
", newsCategory=" + newsCategory +
'}';
}
}
52 changes: 52 additions & 0 deletions src/main/java/de/holarse/backend/db/RevisionedNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.holarse.backend.db;

import jakarta.persistence.*;

@MappedSuperclass
public abstract class RevisionedNode extends TimestampedBase {

@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name="update_userid", referencedColumnName = "id")
private User author;

@Column(name = "nodeid", nullable = false)
private Integer nodeId;

@Column(length = 255)
private String changelog;

@Column(name = "revision", nullable = false)
private Integer revision;

public Integer getNodeId() {
return nodeId;
}

public void setNodeId(Integer nodeId) {
this.nodeId = nodeId;
}

public String getChangelog() {
return changelog;
}

public void setChangelog(String changelog) {
this.changelog = changelog;
}

public Integer getRevision() {
return revision;
}

public void setRevision(Integer revision) {
this.revision = revision;
}

public User getAuthor() {
return author;
}

public void setAuthor(User author) {
this.author = author;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.holarse.backend.db.repositories;

import de.holarse.backend.db.NewsCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface NewsCategoryRepository extends JpaRepository<NewsCategory, Integer> {

@Query("from NewsCategory nc where nc.active order by nc.weight desc, nc.name")
List<NewsCategory> findActiveCategories();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.holarse.backend.db.repositories;

import de.holarse.backend.db.News;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface NewsRepository extends JpaRepository<News, Integer>, NodeAwareRepository {
}
Loading

0 comments on commit 6028ce7

Please sign in to comment.