2022-02-14 14:27:45 +01:00
|
|
|
package de.nclazz.service.mailrelay.domain;
|
2022-02-14 13:49:59 +01:00
|
|
|
|
2022-02-14 19:00:58 +01:00
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
2022-02-14 13:49:59 +01:00
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Data;
|
2022-02-14 17:51:59 +01:00
|
|
|
import lombok.NoArgsConstructor;
|
2022-02-14 13:49:59 +01:00
|
|
|
import lombok.NonNull;
|
2022-02-14 16:11:38 +01:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2022-02-14 17:51:59 +01:00
|
|
|
import org.hibernate.annotations.GenericGenerator;
|
|
|
|
import org.hibernate.annotations.Type;
|
|
|
|
|
|
|
|
import javax.persistence.CollectionTable;
|
|
|
|
import javax.persistence.Column;
|
|
|
|
import javax.persistence.ElementCollection;
|
|
|
|
import javax.persistence.Entity;
|
2022-02-14 19:00:58 +01:00
|
|
|
import javax.persistence.FetchType;
|
2022-02-14 17:51:59 +01:00
|
|
|
import javax.persistence.GeneratedValue;
|
|
|
|
import javax.persistence.Id;
|
|
|
|
import javax.persistence.Index;
|
2022-02-15 16:54:42 +01:00
|
|
|
import javax.persistence.JoinColumn;
|
2022-02-14 17:51:59 +01:00
|
|
|
import javax.persistence.OneToMany;
|
|
|
|
import javax.persistence.Table;
|
2022-02-14 13:49:59 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2022-02-14 17:51:59 +01:00
|
|
|
@Entity
|
|
|
|
@Table(name = "accounts", indexes = @Index(columnList = "token"))
|
2022-02-14 13:49:59 +01:00
|
|
|
@Data
|
2022-02-14 16:11:38 +01:00
|
|
|
@Slf4j
|
2022-02-14 13:49:59 +01:00
|
|
|
@AllArgsConstructor
|
2022-02-14 17:51:59 +01:00
|
|
|
@NoArgsConstructor
|
2022-02-14 19:02:52 +01:00
|
|
|
public class Account {
|
2022-02-14 13:49:59 +01:00
|
|
|
|
2022-02-14 17:51:59 +01:00
|
|
|
@Id
|
|
|
|
@Column(name = "guid", columnDefinition = "char(36)")
|
|
|
|
@GeneratedValue(generator = "uuid")
|
|
|
|
@GenericGenerator(name = "uuid", strategy ="org.hibernate.id.UUIDGenerator")
|
|
|
|
@Type(type = "uuid-char")
|
2022-02-14 13:49:59 +01:00
|
|
|
private UUID guid;
|
2022-02-14 21:46:37 +01:00
|
|
|
|
|
|
|
|
2022-02-14 13:49:59 +01:00
|
|
|
private String name;
|
2022-02-14 21:46:37 +01:00
|
|
|
|
|
|
|
@Column(length = Relay.TOKEN_NUM_CHARS)
|
2022-02-14 13:49:59 +01:00
|
|
|
private String token;
|
|
|
|
|
2022-02-14 19:00:58 +01:00
|
|
|
@ElementCollection(fetch = FetchType.EAGER)
|
2022-02-14 17:51:59 +01:00
|
|
|
@CollectionTable(name = "accounts_receivers")
|
|
|
|
private List<String> receivers;
|
2022-02-14 13:49:59 +01:00
|
|
|
|
2022-02-14 19:00:58 +01:00
|
|
|
@JsonIgnore
|
2022-02-14 17:51:59 +01:00
|
|
|
@OneToMany
|
2022-02-15 16:54:42 +01:00
|
|
|
@JoinColumn(name = "message_guid", referencedColumnName = "guid")
|
2022-02-14 13:49:59 +01:00
|
|
|
private final List<Message> sentMessages = new ArrayList<>();
|
|
|
|
|
2022-02-14 19:02:52 +01:00
|
|
|
public static Account of(@NonNull String name, @NonNull List<String> receivers) {
|
|
|
|
Account account = new Account();
|
2022-02-14 19:00:58 +01:00
|
|
|
account.setName(name);
|
|
|
|
account.setReceivers(receivers);
|
|
|
|
return account;
|
2022-02-14 14:13:26 +01:00
|
|
|
}
|
2022-02-14 19:00:58 +01:00
|
|
|
|
2022-02-14 13:49:59 +01:00
|
|
|
}
|