001// SPDX-License-Identifier: GPL-3.0-or-later 002 003package es.uvigo.esei.sing.textproc.entity; 004 005import javax.persistence.Column; 006import javax.persistence.Id; 007import javax.persistence.MappedSuperclass; 008 009import lombok.AllArgsConstructor; 010import lombok.Getter; 011import lombok.NonNull; 012import lombok.Setter; 013 014/** 015 * Represents the common contract to all processed documents 016 * <p> 017 * Non-abstract subclasses of this class must define a public constructor with a 018 * single {@link Integer} parameter (the primitive type is not allowed), which 019 * is the primary key of the entity, that must initialize any other field to 020 * dummy values. 021 * <p> 022 * They also must define a protected no-argument constructor for JPA. 023 * 024 * @author Alejandro González García 025 * @implNote The implementation of this class is not thread-safe. 026 */ 027@MappedSuperclass 028@AllArgsConstructor 029public abstract class ProcessedDocument { 030 @NonNull @Getter @Id 031 private Integer id; 032 @NonNull @Column(nullable = false) @Getter @Setter 033 private String text; 034 035 /** 036 * Dummy default constructor, to be used by JPA only. 037 */ 038 protected ProcessedDocument() { 039 this.id = Integer.MIN_VALUE; 040 this.text = ""; 041 } 042 043 @Override 044 public String toString() { 045 final StringBuilder stringBuilder = new StringBuilder("- "); 046 047 stringBuilder.append(getClass().getSimpleName()) 048 .append('\n').append("ID: ").append(id) 049 .append('\n').append("Text: ").append(text); 050 051 return stringBuilder.toString(); 052 } 053}