bstlboard-back/src/main/java/de/bstly/board/model/Entry.java

282 lines
4.6 KiB
Java

/**
*
*/
package de.bstly.board.model;
import java.time.Instant;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import com.google.common.collect.Maps;
/**
* The Class Entry.
*/
@Entity
@Table(name = "entries")
@EntityListeners({ AuditingEntityListener.class })
public class Entry {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@Column(name = "author", nullable = false)
private String author;
@Column(name = "created", nullable = false)
private Instant created;
@Enumerated(EnumType.STRING)
@Column(name = "entry_type", nullable = false)
private EntryType entryType;
@Enumerated(EnumType.STRING)
@Column(name = "entry_status", nullable = false, columnDefinition = "varchar(255) default 'NORMAL'")
private EntryStatus entryStatus;
@Column(name = "url")
private String url;
@Column(name = "title", nullable = false)
private String title;
@Lob
@Column(name = "text")
private String text;
@Transient
private Double ranking;
@Transient
private Map<String, Object> metadata;
/**
* Gets the id.
*
* @return the id
*/
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* Gets the author.
*
* @return the author
*/
public String getAuthor() {
return author;
}
/**
* Sets the author.
*
* @param author the new author
*/
public void setAuthor(String author) {
this.author = author;
}
/**
* Gets the created.
*
* @return the created
*/
public Instant getCreated() {
return created;
}
/**
* Sets the created.
*
* @param created the new created
*/
public void setCreated(Instant created) {
this.created = created;
}
/**
* Gets the entry type.
*
* @return the entry type
*/
public EntryType getEntryType() {
return entryType;
}
/**
* Sets the entry type.
*
* @param entryType the new entry type
*/
public void setEntryType(EntryType entryType) {
this.entryType = entryType;
}
/**
* Gets the entry status.
*
* @return the entry status
*/
public EntryStatus getEntryStatus() {
return entryStatus;
}
/**
* Sets the entry status.
*
* @param entryStatus the new entry status
*/
public void setEntryStatus(EntryStatus entryStatus) {
this.entryStatus = entryStatus;
}
/**
* Gets the url.
*
* @return the url
*/
public String getUrl() {
return url;
}
/**
* Sets the url.
*
* @param url the new url
*/
public void setUrl(String url) {
this.url = url;
}
/**
* Gets the title.
*
* @return the title
*/
public String getTitle() {
return title;
}
/**
* Sets the title.
*
* @param title the new title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Gets the text.
*
* @return the text
*/
public String getText() {
return text;
}
/**
* Sets the text.
*
* @param text the new text
*/
public void setText(String text) {
this.text = text;
}
/**
* Gets the ranking.
*
* @return the ranking
*/
public Double getRanking() {
return ranking;
}
/**
* Sets the ranking.
*
* @param ranking the new ranking
*/
public void setRanking(Double ranking) {
this.ranking = ranking;
}
/**
* Gets the metadata.
*
* @return the metadata
*/
public Map<String, Object> getMetadata() {
if (metadata == null) {
metadata = Maps.newHashMap();
}
return metadata;
}
/**
* Sets the metadata.
*
* @param metadata the metadata
*/
public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}
/**
* From ranked entry.
*
* @param rankedEntry the ranked entry
* @return the entry
*/
public static Entry fromRankedEntry(RankedEntry rankedEntry) {
Entry entry = new Entry();
entry.setId(rankedEntry.getId());
entry.setAuthor(rankedEntry.getAuthor());
entry.setCreated(rankedEntry.getCreated());
entry.setEntryType(rankedEntry.getEntry_Type());
entry.setUrl(rankedEntry.getUrl());
entry.setTitle(rankedEntry.getTitle());
entry.setText(rankedEntry.getText());
entry.setRanking(rankedEntry.getRanking());
return entry;
}
}