Document.java
package com.tradecloud.domain.dms;
import com.tradecloud.common.base.PersistenceBase;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.Cascade;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.*;
@SuppressWarnings("serial")
@Entity
@Table(name = "document", uniqueConstraints = {@UniqueConstraint(columnNames = {"key"})})
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Document")
@NamedQueries({@NamedQuery(name = "findDocumentByType", query = "from Document as d where d.documentType = :documentType")})
public class Document extends PersistenceBase implements Comparable<Document> {
private String key;
private String createdBy;
private boolean manuallyCreated;
private Date loadedDate;
private String documentName;
private String uuid;
private boolean onFileSystem;
@Enumerated(EnumType.STRING)
private DocumentState state = DocumentState.CREATED;
@Enumerated(EnumType.STRING)
private DocumentFileNameFormat fileNameFormat;
@OneToOne
private DocumentType documentType;
@OneToMany(fetch = FetchType.EAGER)
@Cascade(value = org.hibernate.annotations.CascadeType.ALL)
private Set<Property> properties = new HashSet<>();
@ManyToOne
private DocumentGroup documentGroup;
private Date reviewedDate;
private String reviewUser;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public DocumentType getDocumentType() {
return documentType;
}
public void setDocumentType(DocumentType documentType) {
this.documentType = documentType;
}
public Set<Property> getProperties() {
return properties;
}
public void setProperties(Set<Property> properties) {
this.properties = properties;
}
public void addProperty(Property property) {
properties.add(property);
}
public List<Property> getPropertiesList() {
ArrayList<Property> list = new ArrayList<>(properties);
Collections.sort(list);
return list;
}
@Override
public boolean equals(final Object other) {
if (!(other instanceof Document castOther))
return false;
return new EqualsBuilder().append(getId(), castOther.getId()).append(getKey(), castOther.getKey())
.append(getDocumentType(), castOther.getDocumentType())
.append(getCreated() != null ? getCreated().getTime() : -1, castOther.getCreated() != null ? castOther.getCreated().getTime() : -1)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(getId()).append(key).append(created).append(documentType).toHashCode();
}
public DocumentGroup getDocumentGroup() {
return documentGroup;
}
public void setDocumentGroup(DocumentGroup documentGroup) {
this.documentGroup = documentGroup;
}
@Override
public int compareTo(Document o) {
if (o != null && o.getId() != null && this.getId() != null) {
return this.getId().compareTo(o.getId());
}
return 0;
}
public boolean isManuallyCreated() {
return manuallyCreated;
}
public void setManuallyCreated(boolean manuallyCreated) {
this.manuallyCreated = manuallyCreated;
}
public Date getLoadedDate() {
return loadedDate;
}
public void setLoadedDate(Date loadedDate) {
this.loadedDate = loadedDate;
}
public String getDocumentName() {
return documentName;
}
public void setDocumentName(String documentName) {
this.documentName = documentName;
}
public DocumentState getState() {
return state;
}
public void setState(DocumentState state) {
this.state = state;
}
public boolean isOnFileSystem() {
return onFileSystem;
}
public void setOnFileSystem(boolean onFileSystem) {
this.onFileSystem = onFileSystem;
}
public Date getReviewedDate() {
return reviewedDate;
}
public void setReviewedDate(Date reviewedDate) {
this.reviewedDate = reviewedDate;
}
public String getReviewUser() {
return reviewUser;
}
public void setReviewUser(String reviewUser) {
this.reviewUser = reviewUser;
}
public DocumentFileNameFormat getFileNameFormat() {
return fileNameFormat;
}
public void setFileNameFormat(DocumentFileNameFormat fileNameFormat) {
this.fileNameFormat = fileNameFormat;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}