io.zenwave360.sdk.mongodb2jdl.Post Maven / Gradle / Ivy
package io.zenwave360.sdk.mongodb2jdl;
import java.io.Serializable;
import java.time.Instant;
import java.util.HashSet;
import java.util.Set;
import javax.validation.constraints.NotNull;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* A Post.
*/
@Document(collection = "post")
public class Post implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String id;
@NotNull(message = "must not be null")
@Field("title")
private String title;
@Field("content")
private String content;
@NotNull(message = "must not be null")
@Field("date")
private Instant date;
@Field("postType")
private PostType postType;
@Field("blog")
@DBRef
private Blog blog;
@Field("tags")
@DBRef
@JsonIgnoreProperties(value = {"posts"}, allowSetters = true)
private Set tags = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here
public String getId() {
return this.id;
}
public Post id(String id) {
this.setId(id);
return this;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return this.title;
}
public Post title(String title) {
this.setTitle(title);
return this;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return this.content;
}
public Post content(String content) {
this.setContent(content);
return this;
}
public void setContent(String content) {
this.content = content;
}
public Instant getDate() {
return this.date;
}
public Post date(Instant date) {
this.setDate(date);
return this;
}
public void setDate(Instant date) {
this.date = date;
}
public Blog getBlog() {
return this.blog;
}
public void setBlog(Blog blog) {
this.blog = blog;
}
public Post blog(Blog blog) {
this.setBlog(blog);
return this;
}
public Set getTags() {
return this.tags;
}
public void setTags(Set tags) {
this.tags = tags;
}
public Post tags(Set tags) {
this.setTags(tags);
return this;
}
public Post addTag(Tag tag) {
this.tags.add(tag);
tag.getPosts().add(this);
return this;
}
public Post removeTag(Tag tag) {
this.tags.remove(tag);
tag.getPosts().remove(this);
return this;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Post)) {
return false;
}
return id != null && id.equals(((Post) o).id);
}
@Override
public int hashCode() {
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
return getClass().hashCode();
}
// prettier-ignore
@Override
public String toString() {
return "Post{" +
"id=" + getId() +
", title='" + getTitle() + "'" +
", content='" + getContent() + "'" +
", date='" + getDate() + "'" +
"}";
}
}