From 7f5d834b13d6af9e7a3bd30b25518693b13cd053 Mon Sep 17 00:00:00 2001 From: veltrup Date: Mon, 21 Nov 2022 15:59:23 +0100 Subject: [PATCH] feat: History entries can also be made about other authenticated subjects. --- .../core/domain/entity/HistoryEntry.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntry.java b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntry.java index 1c740ab..572484a 100644 --- a/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntry.java +++ b/src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/HistoryEntry.java @@ -1,11 +1,13 @@ package com.sitepark.ies.contentrepository.core.domain.entity; import java.io.Serializable; +import java.util.Optional; public final class HistoryEntry implements Serializable { private final long entity; - private final long user; + private final String initiator; + private final Long user; private final long timestamp; private final HistoryEntryType type; private final String comment; @@ -14,6 +16,7 @@ public final class HistoryEntry implements Serializable { private HistoryEntry(Builder builder) { this.entity = builder.entity; + this.initiator = builder.initiator; this.user = builder.user; this.timestamp = builder.timestamp; this.type = builder.type; @@ -24,8 +27,19 @@ public long getEntity() { return entity; } - public long getUser() { - return user; + /** + * The initiator can be a user of a system-service or other subjects who + * could authenticate themselves to work with the system. + */ + public String getInitiator() { + return initiator; + } + + /** + * If the initiator is a user of the IES, this returns the ID of the user. + */ + public Optional getUser() { + return Optional.ofNullable(this.user); } public long getTimestamp() { @@ -51,7 +65,8 @@ public Builder toBuilder() { public static class Builder { private long entity; - private long user; + private String initiator; + private Long user; private long timestamp; private HistoryEntryType type; private String comment; @@ -60,6 +75,7 @@ private Builder() { } private Builder(HistoryEntry historyEntry) { this.entity = historyEntry.entity; + this.initiator = historyEntry.initiator; this.user = historyEntry.user; this.timestamp = historyEntry.timestamp; this.type = historyEntry.type; @@ -71,7 +87,13 @@ public Builder entity(long entity) { return this; } - public Builder user(long user) { + public Builder initiator(String initiator) { + assert initiator != null : "initiator is null"; + this.initiator = initiator; + return this; + } + + public Builder user(Long user) { this.user = user; return this; } @@ -83,13 +105,13 @@ public Builder timestamp(long timestamp) { } public Builder type(HistoryEntryType type) { - assert type != null; + assert type != null : "type is null"; this.type = type; return this; } public Builder comment(String comment) { - assert comment != null; + assert comment != null : "comment is null"; this.comment = comment; return this; }