100 lines
2.2 KiB
Java
100 lines
2.2 KiB
Java
package ru.ulstu.news;
|
|
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import ru.ulstu.meeting.Meeting;
|
|
import ru.ulstu.model.BaseEntity;
|
|
|
|
import javax.persistence.Entity;
|
|
import javax.persistence.Lob;
|
|
import javax.persistence.OneToOne;
|
|
import javax.persistence.Transient;
|
|
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;
|
|
|
|
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
|
|
private Date date;
|
|
|
|
@Lob
|
|
@NotEmpty(message = "Текст новости не может быть пустым")
|
|
private String text;
|
|
|
|
private String imageFileName;
|
|
|
|
@Transient
|
|
private MultipartFile imageFile;
|
|
|
|
@OneToOne(mappedBy = "news")
|
|
private Meeting meeting;
|
|
|
|
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 getImageFileName() {
|
|
return imageFileName;
|
|
}
|
|
|
|
public void setImageFileName(String imageFileName) {
|
|
this.imageFileName = imageFileName;
|
|
}
|
|
|
|
public MultipartFile getImageFile() {
|
|
return imageFile;
|
|
}
|
|
|
|
public void setImageFile(MultipartFile imageFile) {
|
|
this.imageFile = imageFile;
|
|
}
|
|
|
|
public Meeting getMeeting() {
|
|
return meeting;
|
|
}
|
|
|
|
public void setMeeting(Meeting meeting) {
|
|
this.meeting = meeting;
|
|
}
|
|
|
|
public String getPreview() {
|
|
return text != null && text.length() > MAX_NEWS_TEXT_PREVIEW_LENGTH
|
|
? text.substring(0, MAX_NEWS_TEXT_PREVIEW_LENGTH) + "..."
|
|
: text;
|
|
}
|
|
}
|