Files
no-copy/src/main/java/ru/soune/nocopy/entity/file/FileEntity.java
T

117 lines
3.0 KiB
Java
Raw Normal View History

2025-12-17 22:37:46 +07:00
package ru.soune.nocopy.entity.file;
2025-12-17 01:19:48 +07:00
import com.fasterxml.jackson.annotation.JsonIgnore;
2025-12-17 01:19:48 +07:00
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;
2026-02-24 18:35:35 +07:00
import java.util.concurrent.atomic.AtomicInteger;
2025-12-17 01:19:48 +07:00
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "file_entities")
@EntityListeners(AuditingEntityListener.class)
public class FileEntity {
2026-02-24 18:35:35 +07:00
private static AtomicInteger supportIdCounter = new AtomicInteger(0);
2025-12-17 01:19:48 +07:00
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private String id;
2026-01-20 21:55:42 +07:00
@Column(name = "support_id", unique = true, updatable = false)
private Integer supportId;
2025-12-17 01:19:48 +07:00
@Column(name = "user_id", nullable = false)
private Long userId;
@Column(name = "original_file_name", nullable = false)
private String originalFileName;
@Column(name = "stored_file_name", nullable = false)
private String storedFileName;
@Column(name = "file_path", nullable = false, unique = true)
private String filePath;
@Column(name = "file_size", nullable = false)
private Long fileSize;
@Column(name = "mime_type")
private String mimeType;
@Column(name = "file_extension")
private String fileExtension;
@Column(name = "checksum")
private String checksum;
@Column(name = "upload_session_id")
private String uploadSessionId;
@Enumerated(EnumType.STRING)
@Column(name = "status")
private FileStatus status;
@CreatedDate
@Column(name = "created_at", updatable = false)
private LocalDateTime createdAt;
@LastModifiedDate
@Column(name = "updated_at")
private LocalDateTime updatedAt;
2026-01-08 03:22:32 +07:00
@Column(name = "protected_file_path")
private String protectedFilePath;
@Column(name = "protection_status")
@Enumerated(EnumType.STRING)
private ProtectionStatus protectionStatus;
@Column(name = "protected_at")
private LocalDateTime protectedAt;
@Column(name = "signature")
@JsonIgnore
private String signature;
@OneToOne(mappedBy = "file", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
private ImageHashEntity imageHash;
2025-12-17 01:19:48 +07:00
@PrePersist
public void prePersist() {
2026-02-24 18:35:35 +07:00
if (this.supportId == null) {
this.supportId = supportIdCounter.incrementAndGet();
}
2025-12-17 01:19:48 +07:00
if (this.status == null) {
this.status = FileStatus.ACTIVE;
}
2026-01-08 03:22:32 +07:00
if (this.protectionStatus == null) {
this.protectionStatus = ProtectionStatus.NOT_PROTECTED;
}
2025-12-17 01:19:48 +07:00
if (this.createdAt == null) {
this.createdAt = LocalDateTime.now();
}
this.updatedAt = LocalDateTime.now();
}
@PreUpdate
public void preUpdate() {
this.updatedAt = LocalDateTime.now();
}
2026-02-24 18:35:35 +07:00
public static void initializeCounter(int maxId) {
supportIdCounter = new AtomicInteger(maxId);
}
2025-12-17 01:19:48 +07:00
}