All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.base.model.Document Maven / Gradle / Ivy

There is a newer version: 1.17.5
Show newest version
package com.xlrit.gears.base.model;

import java.time.OffsetDateTime;
import java.util.Objects;

import com.xlrit.gears.base.content.ContentRef;
import com.xlrit.gears.base.meta.*;
import com.xlrit.gears.base.util.DisplayedHelper;
import jakarta.persistence.*;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

/**
 * DOCUMENT in DOCUMENTS =
 *     title           : text
 *     filename        : text
 *     type            : text
 *     template        : text
 *     parameters      : tuple
 */
@EntityType(typeName = "DOCUMENT", collectionName = "DOCUMENTS")
@Attributes({
	"title",
	"filename",
	"type",
	"template",
	"parameters",
	"contentRef",
	"creator",
	"createdAt",
	"modifier",
	"modifiedAt",
	"publisher",
	"publishedAt",
})
@Entity
@Table(name = "SYS_DOCUMENT")
public class Document implements Identifiable, Auditable, Publishable {

	@Getter
	@Id @Column(name = "id_", length = 26)
	private String id;

	@Getter @Setter
	@Attribute(formalName = "title", type = DataType.TEXT, label = "Title")
	@Basic @Column(name = "title_")
	private String title;

	@Getter @Setter
	@Attribute(formalName = "filename", type = DataType.TEXT, label = "Title")
	@Basic @Column(name = "filename_")
	private String filename;

	@Getter @Setter
	@Attribute(formalName = "type", type = DataType.TEXT, label = "Type")
	@Basic @Column(name = "type_")
	private String type;

	@Getter @Setter
	@Attribute(formalName = "template", type = DataType.TEXT, label = "Template")
	@Basic @Column(name = "template_")
	private String template;

	@Getter @Setter
	@Attribute(formalName = "content", type = DataType.FILE, label = "Content")
	@Column(name = "content_ref_")
	@JdbcTypeCode(SqlTypes.JSON)
	private ContentRef contentRef;

	@Getter @Setter
	@Attribute(formalName = "parameters", type = DataType.TUPLE, label = "Parameters")
	@Transient // TODO store as JSON
	private Object parameters;

	@Getter @Setter
	@Attribute(formalName = "CREATOR", type = DataType.ENTITY, label = "Creator")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "creator_id_")
	private User creator;

	@Getter @Setter
	@Attribute(formalName = "created_at", type = DataType.DATETIME, label = "Created at")
	@Basic @Column(name = "created_at_")
	private OffsetDateTime createdAt;

	@Getter @Setter
	@Attribute(formalName = "MODIFIER", type = DataType.ENTITY, label = "Modifier")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "modifier_id_")
	private User modifier;

	@Getter @Setter
	@Attribute(formalName = "modified_at", type = DataType.DATETIME, label = "Modified at")
	@Basic @Column(name = "modified_at_")
	private OffsetDateTime modifiedAt;

	@Getter @Setter
	@Attribute(formalName = "PUBLISHER", type = DataType.ENTITY, label = "Publisher")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "publisher_id_")
	private User publisher;

	@Getter @Setter
	@Attribute(formalName = "published_at", type = DataType.DATETIME, label = "Published at")
	@Basic @Column(name = "published_at_")
	private OffsetDateTime publishedAt;

	public Document() {}
	public Document(String id) { this.id = id; }

	@Override
	public boolean equals(Object obj) {
		if (this.id == null) return super.equals(obj);
		if (!(obj instanceof Document 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("Title", this.title)
			.add("Type", this.type)
			.add("Filename", this.filename)
			.add("Template", this.template)
			.add("Content", this.contentRef != null ? contentRef.getId() : "-")
			.toString();
	}

	@Override
	public String toString() {
		return "Document[" + this.defaultDisplayed() + "]";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy