org.vader.ecm.domain.Document.java Source code

Java tutorial

Introduction

Here is the source code for org.vader.ecm.domain.Document.java

Source

/*
 * Copyright 2014. Vadim Baranov
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.vader.ecm.domain;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.joda.time.DateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

/**
 * @author Vadim Baranov
 */
@Entity
@Table(name = "documents")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Document implements Serializable {
    private static final long serialVersionUID = 3755138675306466140L;

    private static final String[] EXTERNAL_FIELDS = { "id", "contractors", "creator" };

    @Id
    @SequenceGenerator(name = "documents_seq", sequenceName = "documents_seq")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "documents_seq")
    @Column(name = "id")
    private Long id;

    @Column(name = "create_ts", nullable = false)
    private DateTime createTs;

    @Column(name = "author_id", nullable = false)
    private Long authorId;

    @Column(name = "title", length = 512, nullable = false)
    private String title;

    @Column(name = "subject", length = 4000)
    private String subject;

    @Column(name = "signature", nullable = false)
    private byte[] signature;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "template_id")
    private DocumentTemplate template;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "creator_id")
    private Party creator;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "document_contractors", joinColumns = @JoinColumn(name = "document_id"), inverseJoinColumns = @JoinColumn(name = "party_id"))
    private Collection<Party> contractors = new ArrayList<>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public DateTime getCreateTs() {
        return createTs;
    }

    public void setCreateTs(DateTime creationDate) {
        this.createTs = creationDate;
    }

    public Long getAuthorId() {
        return authorId;
    }

    public void setAuthorId(Long authorId) {
        this.authorId = authorId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public byte[] getSignature() {
        return signature;
    }

    public void setSignature(byte[] signature) {
        this.signature = signature;
    }

    public DocumentTemplate getTemplate() {
        return template;
    }

    public void setTemplate(DocumentTemplate template) {
        this.template = template;
    }

    public Party getCreator() {
        return creator;
    }

    public void setCreator(Party creator) {
        this.creator = creator;
    }

    public Collection<Party> getContractors() {
        return contractors;
    }

    public void setContractors(Collection<Party> contractors) {
        this.contractors = contractors;
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this, EXTERNAL_FIELDS);
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj, EXTERNAL_FIELDS);
    }

    @Override
    public String toString() {
        final ReflectionToStringBuilder sb = new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
        sb.setExcludeFieldNames(EXTERNAL_FIELDS);
        return sb.toString();
    }
}