I've dynamoDB database, in which I've a table named user
. I want to log auditing (CreatedBy
, LastModifiedBy
, CreatedDate
, LastModifiedDate
)in this table.
I've found JPA auditing (from here) and MongoDB auditing with annotations @EnableJpaAuditing
and @EnableMongoAuditing
respectively. But obviously they are not working with dynamoDB.
Here is my abstract class for auditing:
@DynamoDBDocument
public abstract class PQSSAbstractAuditingEntity implements Serializable{
@CreatedBy
@JsonIgnore
@DynamoDBAttribute
private String createdBy;
@LastModifiedBy
@JsonIgnore
@DynamoDBAttribute
private String lastModifiedBy;
@CreatedDate
@JsonIgnore
@DynamoDBAttribute
private Date createdDate;
@LastModifiedDate
@JsonIgnore
@DynamoDBAttribute
private Date lastModifiedDate = new Date();
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public String getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Date getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
I've assigned dates to respective fields but I've to set createdBy
and lastModifiedBy
depending on the logged in user. So I've to fetch the dynamically at runtime, when ever new entry is added into the database.
I know how to set these fields statically but the problem is how to make annotations aware of these changes at run time.
As I mentioned, I've found AuditAware
for JPA and mongo. I need the same for dynamoDB.
Any help will be appreciated. As I'm new to Spring boot.