diff --git a/src/main/java/tech/ailef/dbadmin/external/controller/DefaultDbAdminController.java b/src/main/java/tech/ailef/dbadmin/external/controller/DefaultDbAdminController.java index 98ff9d2..5d38673 100644 --- a/src/main/java/tech/ailef/dbadmin/external/controller/DefaultDbAdminController.java +++ b/src/main/java/tech/ailef/dbadmin/external/controller/DefaultDbAdminController.java @@ -280,7 +280,7 @@ public class DefaultDbAdminController { attr.addFlashAttribute("error", e.getMessage()); } - saveAction(new UserAction(schema.getTableName(), id, "DELETE")); + saveAction(new UserAction(schema.getTableName(), id, "DELETE", schema.getClassName())); return "redirect:/" + properties.getBaseUrl() + "/model/" + className; } @@ -310,7 +310,7 @@ public class DefaultDbAdminController { attr.addFlashAttribute("message", "Deleted " + countDeleted + " of " + ids.length + " items"); for (String id : ids) { - saveAction(new UserAction(schema.getTableName(), id, "DELETE")); + saveAction(new UserAction(schema.getTableName(), id, "DELETE", schema.getClassName())); } return "redirect:/" + properties.getBaseUrl() + "/model/" + className; @@ -375,7 +375,7 @@ public class DefaultDbAdminController { repository.attachManyToMany(schema, newPrimaryKey, multiValuedParams); pkValue = newPrimaryKey.toString(); attr.addFlashAttribute("message", "Item created successfully."); - saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE")); + saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName())); } catch (DataIntegrityViolationException e) { attr.addFlashAttribute("errorTitle", "Unable to INSERT row"); attr.addFlashAttribute("error", e.getMessage()); @@ -399,7 +399,7 @@ public class DefaultDbAdminController { repository.update(schema, params, files); repository.attachManyToMany(schema, pkValue, multiValuedParams); attr.addFlashAttribute("message", "Item saved successfully."); - saveAction(new UserAction(schema.getTableName(), pkValue, "EDIT")); + saveAction(new UserAction(schema.getTableName(), pkValue, "EDIT", schema.getClassName())); } catch (DataIntegrityViolationException e) { attr.addFlashAttribute("errorTitle", "Unable to UPDATE row (no changes applied)"); attr.addFlashAttribute("error", e.getMessage()); @@ -415,7 +415,7 @@ public class DefaultDbAdminController { Object newPrimaryKey = repository.create(schema, params, files, pkValue); repository.attachManyToMany(schema, newPrimaryKey, multiValuedParams); attr.addFlashAttribute("message", "Item created successfully"); - saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE")); + saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName())); } catch (DataIntegrityViolationException e) { attr.addFlashAttribute("errorTitle", "Unable to INSERT row (no changes applied)"); attr.addFlashAttribute("error", e.getMessage()); diff --git a/src/main/java/tech/ailef/dbadmin/internal/model/UserAction.java b/src/main/java/tech/ailef/dbadmin/internal/model/UserAction.java index f76491d..821e0a0 100644 --- a/src/main/java/tech/ailef/dbadmin/internal/model/UserAction.java +++ b/src/main/java/tech/ailef/dbadmin/internal/model/UserAction.java @@ -2,6 +2,7 @@ package tech.ailef.dbadmin.internal.model; import java.time.LocalDateTime; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.datetime.standard.DateTimeFormatterFactory; import jakarta.persistence.Column; @@ -10,6 +11,9 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Lob; +import jakarta.persistence.Transient; +import tech.ailef.dbadmin.external.DbAdmin; +import tech.ailef.dbadmin.external.dbmapping.DbObjectSchema; /** * An action executed by any user from the web UI. @@ -28,6 +32,9 @@ public class UserAction { @Column(nullable = false) private String sql; + @Column(nullable = false) + private String javaClass; + @Column(nullable = false) private String onTable; @@ -40,9 +47,10 @@ public class UserAction { public UserAction() { } - public UserAction(String onTable, String primaryKey, String actionType) { + public UserAction(String onTable, String primaryKey, String actionType, String javaClass) { this.createdAt = LocalDateTime.now(); this.sql = "SQL TODO"; + this.javaClass = javaClass; this.onTable = onTable; this.actionType = actionType; this.primaryKey = primaryKey; @@ -99,4 +107,12 @@ public class UserAction { public String getFormattedDate() { return new DateTimeFormatterFactory("YYYY-MM-dd HH:mm:ss").createDateTimeFormatter().format(createdAt); } + + public String getJavaClass() { + return javaClass; + } + + public void setJavaClass(String javaClass) { + this.javaClass = javaClass; + } } diff --git a/src/main/resources/templates/logs.html b/src/main/resources/templates/logs.html index 4b46fea..ec10a29 100644 --- a/src/main/resources/templates/logs.html +++ b/src/main/resources/templates/logs.html @@ -109,7 +109,14 @@