Skip to content

Commit

Permalink
Auditing
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Sep 22, 2023
1 parent 5bd1e2c commit c2362ac
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 35 deletions.
29 changes: 0 additions & 29 deletions src/main/java/jasper/domain/AbstractAuditingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.time.Instant;

/**
* Base abstract class for entities which will hold definitions for created, last modified, created by,
Expand All @@ -28,21 +25,11 @@ public abstract class AbstractAuditingEntity implements Serializable {
@JsonIgnore
private String createdBy;

@CreatedDate
@Column(name = "created_date", updatable = false)
@JsonIgnore
private Instant createdDate = Instant.now();

@LastModifiedBy
@Column(name = "last_modified_by", length = 50)
@JsonIgnore
private String lastModifiedBy;

@LastModifiedDate
@Column(name = "last_modified_date")
@JsonIgnore
private Instant lastModifiedDate = Instant.now();

public String getCreatedBy() {
return createdBy;
}
Expand All @@ -51,27 +38,11 @@ public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}

public Instant getCreatedDate() {
return createdDate;
}

public void setCreatedDate(Instant createdDate) {
this.createdDate = createdDate;
}

public String getLastModifiedBy() {
return lastModifiedBy;
}

public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}

public Instant getLastModifiedDate() {
return lastModifiedDate;
}

public void setLastModifiedDate(Instant lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
2 changes: 1 addition & 1 deletion src/main/java/jasper/domain/Ext.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@TypeDefs({
@TypeDef(name = "json", typeClass = JsonType.class)
})
public class Ext implements Tag {
public class Ext extends AbstractAuditingEntity implements Tag {
public static final int NAME_LEN = 512;

@Id
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jasper/domain/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Metadata {
private Map<String, List<String>> plugins;
private boolean obsolete = false;

// TODO: other origins (And dedupe check)

public void addResponse(String url) {
if (responses == null) {
responses = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jasper/domain/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@TypeDefs({
@TypeDef(name = "json", typeClass = JsonType.class)
})
public class Plugin implements Tag {
public class Plugin extends AbstractAuditingEntity implements Tag {
public static final String REGEX = "[_+]?plugin(?:/[a-z0-9]+(?:[./][a-z0-9]+)*)?";
public static final String QTAG_REGEX = REGEX + HasOrigin.REGEX;
public static final int NAME_LEN = 512;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jasper/domain/Ref.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@TypeDef(name = "json", typeClass = JsonType.class),
@TypeDef(name = "tsvector", typeClass = PostgreSQLTSVectorType.class)
})
public class Ref implements HasTags {
public class Ref extends AbstractAuditingEntity implements HasTags {
public static final String REGEX = "^[^:/?#]+:(?://[^/?#]*)?[^?#]*(?:\\?[^#]*)?(?:#.*)?";
public static final String SCHEME_REGEX = "^[^:/?#]+:";
public static final int URL_LEN = 4096;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jasper/domain/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@TypeDefs({
@TypeDef(name = "json", typeClass = JsonType.class)
})
public class Template implements Tag {
public class Template extends AbstractAuditingEntity implements Tag {
public static final String REGEX = "(?:_?[a-z0-9]+(?:[./][a-z0-9]+)*)?";
public static final String QTAG_REGEX = REGEX + HasOrigin.REGEX;
public static final int NAME_LEN = 512;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jasper/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@TypeDefs({
@TypeDef(name = "json", typeClass = JsonType.class)
})
public class User implements Tag {
public class User extends AbstractAuditingEntity implements Tag {
public static final String REGEX = "[_+]user(?:/[a-z0-9]+(?:[./][a-z0-9]+)*)?";
public static final String ROLE_REGEX = "\\w*";
public static final String QTAG_REGEX = REGEX + HasOrigin.REGEX;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jasper/domain/Web.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Entity
@Getter
@Setter
public class Web {
public class Web extends AbstractAuditingEntity {

@Id
@Column(updatable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd">

<changeSet author="chris" id="00000000000003" dbms="postgresql">
<addColumn tableName="ref">
<column name="created_by" type="text"/>
<column name="last_modified_by" type="text"/>
</addColumn>
<addColumn tableName="ext">
<column name="created_by" type="text"/>
<column name="last_modified_by" type="text"/>
</addColumn>
<addColumn tableName="users">
<column name="created_by" type="text"/>
<column name="last_modified_by" type="text"/>
</addColumn>
<addColumn tableName="plugin">
<column name="created_by" type="text"/>
<column name="last_modified_by" type="text"/>
</addColumn>
<addColumn tableName="template">
<column name="created_by" type="text"/>
<column name="last_modified_by" type="text"/>
</addColumn>
<addColumn tableName="web">
<column name="created_by" type="text"/>
<column name="last_modified_by" type="text"/>
</addColumn>
</changeSet>

</databaseChangeLog>

0 comments on commit c2362ac

Please sign in to comment.