60 lines
1.3 KiB
Java
60 lines
1.3 KiB
Java
package ru.ulstu.model;
|
|
|
|
import javax.persistence.Entity;
|
|
import javax.persistence.Lob;
|
|
import javax.validation.constraints.NotEmpty;
|
|
import java.util.Date;
|
|
|
|
@Entity
|
|
public class News extends BaseEntity {
|
|
private final static int MAX_NEWS_TEXT_PREVIEW_LENGTH = 800;
|
|
|
|
@NotEmpty(message = "Заголовок не может быть пустым")
|
|
private String title;
|
|
|
|
private Date date;
|
|
|
|
@Lob
|
|
@NotEmpty(message = "Текст новости не может быть пустым")
|
|
private String text;
|
|
|
|
public News() {
|
|
}
|
|
|
|
public News(String title, Date date, String text) {
|
|
this.title = title;
|
|
this.date = date;
|
|
this.text = text;
|
|
}
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
public Date getDate() {
|
|
return date;
|
|
}
|
|
|
|
public void setDate(Date date) {
|
|
this.date = date;
|
|
}
|
|
|
|
public void setTitle(String title) {
|
|
this.title = title;
|
|
}
|
|
|
|
public void setText(String text) {
|
|
this.text = text;
|
|
}
|
|
|
|
public String getText() {
|
|
return text;
|
|
}
|
|
|
|
public String getPreview() {
|
|
return text != null && text.length() > MAX_NEWS_TEXT_PREVIEW_LENGTH
|
|
? text.substring(0, MAX_NEWS_TEXT_PREVIEW_LENGTH) + "..."
|
|
: text;
|
|
}
|
|
}
|