org.genesys.blocks.auditlog.model.AuditLog Maven / Gradle / Ivy
/*
* Copyright 2018 Global Crop Diversity Trust
*
* 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.genesys.blocks.auditlog.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.genesys.blocks.auditlog.annotations.NotAudited;
import org.genesys.blocks.model.ClassPK;
import org.genesys.blocks.model.EmptyModel;
import org.genesys.blocks.util.JsonSidConverter;
import org.hibernate.annotations.Type;
import org.springframework.data.annotation.CreatedBy;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant;
/**
* The Class AuditLog.
*/
@Entity
@Table(name = "auditlog", indexes = { @Index(unique = false, columnList = "entityId, classPk, prop") })
@NotAudited
public class AuditLog extends EmptyModel {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -2254427722756061411L;
public static final String FIELD_VALUE_NOT_AUDITED = "__FIELD_VALUE_NOT_AUDITED__";
/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, length = 20)
protected Long id;
/** The created by. */
@CreatedBy
@JsonSerialize(converter = JsonSidConverter.class)
private Long createdBy;
/** The log date. */
@Column(name = "logdate", nullable = false)
private Instant logDate;
/** Class name of the referenced entity. */
@ManyToOne(optional = false)
@JoinColumn(name = "classPk")
private ClassPK classPk;
/** ID of the referenced entity. */
@Column(name = "entityId")
private long entityId;
/** The name of the property modified. */
@Column(nullable = false, name = "prop", length = 50)
private String propertyName;
/** The type of entity referenced in the changed property. */
@ManyToOne(optional = true)
@JoinColumn(name = "entityClassPk")
private ClassPK referencedEntity;
/** String representation of the previous state. */
@Lob
@Column(nullable = true)
@Type(type = "org.hibernate.type.TextType")
private String previousState;
/** String representation of the updated state. */
@Lob
@Column(nullable = true)
@Type(type = "org.hibernate.type.TextType")
private String newState;
/** The action. */
@Enumerated(EnumType.STRING)
@Column(length = 10, nullable = false, updatable = false)
private AuditAction action;
/** The previous entity. */
@Transient
@JsonProperty
private Object previousEntity;
/** The next entity. */
@Transient
@JsonProperty
private Object newEntity;
/**
* Instantiates a new AuditLog object.
*/
public AuditLog() {
}
/**
* Makes a deep copy of an existing AuditLog object.
*
* @param source The AuditLog to copy
*/
public AuditLog(AuditLog source) {
this.id = source.getId();
this.createdBy = source.getCreatedBy();
this.logDate = source.getLogDate();
this.classPk = source.getClassPk();
this.entityId = source.getEntityId();
this.propertyName = source.getPropertyName();
this.referencedEntity = source.getReferencedEntity();
this.previousState = source.getPreviousState();
this.newState = source.getNewState();
this.action = source.getAction();
this.previousEntity = source.getPreviousEntity();
this.newEntity = source.getNewEntity();
}
/**
* Gets the id.
*
* @return the id
*/
@Override
public Long getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
protected void setId(final Long id) {
this.id = id;
}
/**
* Gets the created by.
*
* @return the created by
*/
public Long getCreatedBy() {
return createdBy;
}
/**
* Sets the created by.
*
* @param createdBy the new created by
*/
protected void setCreatedBy(final Long createdBy) {
this.createdBy = createdBy;
}
/**
* Gets the log created date.
*
* @return the log date
*/
public Instant getLogDate() {
return logDate;
}
/**
* Sets the log create date.
*
* @param logDate the log date
*/
public void setLogDate(final Instant logDate) {
this.logDate = logDate;
}
/**
* Gets the class pk.
*
* @return the class pk
*/
public ClassPK getClassPk() {
return classPk;
}
/**
* Sets the class pk.
*
* @param classPk the new class pk
*/
public void setClassPk(final ClassPK classPk) {
this.classPk = classPk;
}
/**
* Gets the entity id.
*
* @return the entity id
*/
public long getEntityId() {
return entityId;
}
/**
* Sets the entity id.
*
* @param entityId the new entity id
*/
public void setEntityId(final long entityId) {
this.entityId = entityId;
}
/**
* Sets the property name.
*
* @param propertyName the new property name
*/
public void setPropertyName(final String propertyName) {
this.propertyName = propertyName;
}
/**
* Gets the property name.
*
* @return the property name
*/
public String getPropertyName() {
return propertyName;
}
/**
* Sets the referenced entity.
*
* @param referencedEntity the new referenced entity
*/
public void setReferencedEntity(final ClassPK referencedEntity) {
this.referencedEntity = referencedEntity;
}
/**
* Gets the referenced entity.
*
* @return the referenced entity
*/
public ClassPK getReferencedEntity() {
return referencedEntity;
}
/**
* Sets the previous state.
*
* @param previousState the new previous state
*/
public void setPreviousState(final String previousState) {
this.previousState = previousState;
}
/**
* Gets the previous state.
*
* @return the previous state
*/
public String getPreviousState() {
return previousState;
}
/**
* Sets the new state.
*
* @param newState the new new state
*/
public void setNewState(final String newState) {
this.newState = newState;
}
/**
* Gets the new state.
*
* @return the new state
*/
public String getNewState() {
return newState;
}
/**
* Sets the action.
*
* @param action the new action
*/
public void setAction(final AuditAction action) {
this.action = action;
}
/**
* Gets the action.
*
* @return the action
*/
public AuditAction getAction() {
return action;
}
/**
* Sets the previous entity.
*
* @param entity the new previous entity
*/
public void setPreviousEntity(Object entity) {
this.previousEntity = entity;
}
/**
* Gets the previous entity.
*
* @return the previous entity
*/
public Object getPreviousEntity() {
return previousEntity;
}
/**
* Sets the new entity.
*
* @param newEntity the new new entity
*/
public void setNewEntity(Object newEntity) {
this.newEntity = newEntity;
}
/**
* Gets the new entity.
*
* @return the new entity
*/
public Object getNewEntity() {
return newEntity;
}
}