All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.xlrit.gears.base.model.Message Maven / Gradle / Ivy
package com.xlrit.gears.base.model;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import com.xlrit.gears.base.content.ContentRef;
import com.xlrit.gears.base.meta.*;
import jakarta.persistence.*;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;
/*
MESSAGE in MESSAGES =
SENDER : USER
RECIPIENT : USER
title : text
body : text multiline
attachments : multiple file optional
*/
@EntityType(typeName = "MESSAGE", collectionName = "MESSAGES")
@Attributes({ "sender", "recipient", "subject", "body", "attachments" })
@Entity
@Table(name = "SYS_MESSAGE")
public class Message implements Identifiable, Auditable, Publishable {
@Getter
@Id @Column(name = "id_", length = 26)
private String id;
@Getter @Setter
@Attribute(formalName = "SENDER", type = DataType.ENTITY, label = "Sender")
@ManyToOne(fetch = FetchType.LAZY)
private User sender;
@Getter @Setter
@Attribute(formalName = "RECIPIENT", type = DataType.ENTITY, label = "Recipient")
@ManyToOne(fetch = FetchType.LAZY)
private User recipient;
@Getter @Setter
@Attribute(formalName = "subject", type = DataType.TEXT, label = "Subject")
@Basic @Column(name = "subject_")
private String subject;
@Getter @Setter
@Attribute(formalName = "body", type = DataType.TEXT, label = "Body")
@Trait("multiline")
@Basic @Column(name = "body_", length = 32700)
private String body;
@Getter @Setter
@Attribute(formalName = "ATTACHMENTS", type = DataType.ENTITY, label = "Attachments")
@Basic @Column(name = "attachments_")
@JdbcTypeCode(SqlTypes.JSON)
private List attachments;
@Getter @Setter
@Basic @Column(name = "read_at_")
private OffsetDateTime readAt;
@Getter @Setter
@Basic @Column(name = "process_instance_id")
private String processInstanceId;
@Getter @Setter
@Basic @Column(name = "process_definition_id")
private String processDefinitionId;
@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 Message() {}
public Message(String id) {
this.id = id;
this.attachments = new ArrayList<>();
}
public boolean forUser(String userId) {
return recipient != null && Objects.equals(recipient.getId(), userId);
}
@Override
public boolean equals(Object obj) {
if (this.id == null) return super.equals(obj);
if (!(obj instanceof Message that)) return false;
return Objects.equals(this.id, that.getId());
}
@Override
public int hashCode() {
return Objects.hash(this.id);
}
@Displayed
public String defaultDisplayed() {
return "title: " + subject;
}
@Override
public String toString() {
return "Message[" + defaultDisplayed() + "]";
}
}