AuthorRef.java

/*
 * Copyright © 2012-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */
package org.ctan.site.domain.catalogue;

import org.ctan.site.domain.AbstractEntity;

import com.fasterxml.jackson.annotation.JsonManagedReference;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder.Default;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * The class <code>AuthorRef</code> contains the association of a package to an
 * author.
 *
 * @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
 */
@Entity
@Table(name = "author_ref")
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@SuppressFBWarnings(value = "EI_EXPOSE_REP")
public class AuthorRef extends AbstractEntity {

    /**
     * The field <code>pkg</code> contains the associated package.
     */
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    @JsonManagedReference
    private Pkg pkg;

    /**
     * The field <code>author</code> contains the associated author.
     */
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Author author;

    /**
     * The field <code>active</code> contains the indicator whether the author
     * is (still) known to be active.
     */
    @Column
    @Default
    private boolean active = true;

    /**
     * {@inheritDoc}
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {

        return author.getKey() + " " + (active ? "active" : "inactive");
    }
}