com.xlrit.gears.base.model.ContentEntity Maven / Gradle / Ivy
package com.xlrit.gears.base.model;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.time.OffsetDateTime;
import java.util.Objects;
import com.xlrit.gears.base.content.Content;
import com.xlrit.gears.base.meta.Displayed;
import com.xlrit.gears.base.util.DisplayedHelper;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
@Entity
@Table(name = "SYS_CONTENT")
public class ContentEntity implements Identifiable, Auditable, Content {
@Getter
@Id @Column(name = "id_", length = 26)
private String id;
@Getter @Setter
@Basic @Column(name = "filename_")
private String filename;
@Getter @Setter
@Basic @Column(name = "content_type_")
private String contentType;
@Getter @Setter
@Basic @Column(name = "size_")
private int size;
@Getter @Setter
@Basic
@Lob @Column(name = "data_")
private byte[] data;
@Getter @Setter
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "creator_id_")
private User creator;
@Getter @Setter
@Basic @Column(name = "created_at_")
private OffsetDateTime createdAt;
@Getter @Setter
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "modifier_id_")
private User modifier;
@Getter @Setter
@Basic @Column(name = "modified_at_")
private OffsetDateTime modifiedAt;
public ContentEntity() {}
public ContentEntity(String id) { this.id = id; }
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(data);
}
@Override
public boolean equals(Object obj) {
if (this.id == null) return super.equals(obj);
if (!(obj instanceof ContentEntity that)) return false;
return Objects.equals(this.id, that.getId());
}
@Override
public int hashCode() {
return Objects.hash(this.id);
}
@Displayed
public String defaultDisplayed() {
return new DisplayedHelper()
.add("Filename", this.filename)
.add("ContentType", this.contentType)
.toString();
}
@Override
public String toString() {
return "Content[" + this.defaultDisplayed() + "]";
}
}