package com.xfestudio.xfeservermanager.core.content;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
/** Revisioned draft. Publishing and activation are deliberately separate from saving. */
public record ContentWorkspace(int schemaVersion, long revision, boolean enabled,
List<ContentDefinition> definitions, Instant updatedAt, String updatedBy) {
public static final int SCHEMA_VERSION = 1;
public static final int MAX_DEFINITIONS = 256;
public static final int MAX_TEXT_CHARACTERS = 262_144;
public ContentWorkspace {
if (schemaVersion != SCHEMA_VERSION) throw new IllegalArgumentException("unsupported content schemaVersion");
if (revision < 0) throw new IllegalArgumentException("content revision must not be negative");
definitions = definitions == null ? List.of() : List.copyOf(definitions);
if (definitions.size() > MAX_DEFINITIONS) throw new IllegalArgumentException("content limit exceeded (256)");
var ids = new HashSet<String>();
long characters = 0;
for (ContentDefinition definition : definitions) {
if (!ids.add(definition.id())) throw new IllegalArgumentException("duplicate content id: " + definition.id());
characters += definition.id().length() + definition.name().length() + definition.description().length();
characters += definition.properties().entrySet().stream().mapToLong(e -> e.getKey().length() + e.getValue().length()).sum();
for (var behavior : definition.behaviors()) {
characters += behavior.id().length() + behavior.event().length() + behavior.action().length();
characters += behavior.parameters().entrySet().stream().mapToLong(e -> e.getKey().length() + e.getValue().length()).sum();
}
}
if (characters > MAX_TEXT_CHARACTERS) throw new IllegalArgumentException("content workspace text budget exceeded");
Objects.requireNonNull(updatedAt, "content updatedAt");
updatedBy = ContentDefinition.text(updatedBy, "content actor", 1, 128);
}
}
package com.xfestudio.xfeservermanager.core.content;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
/** Revisioned draft. Publishing and activation are deliberately separate from saving. */
public record ContentWorkspace(int schemaVersion, long revision, boolean enabled,
List<ContentDefinition> definitions, Instant updatedAt, String updatedBy) {
public static final int SCHEMA_VERSION = 1;
public static final int MAX_DEFINITIONS = 256;
public static final int MAX_TEXT_CHARACTERS = 262_144;
public ContentWorkspace {
if (schemaVersion != SCHEMA_VERSION) throw new IllegalArgumentException("unsupported content schemaVersion");
if (revision < 0) throw new IllegalArgumentException("content revision must not be negative");
definitions = definitions == null ? List.of() : List.copyOf(definitions);
if (definitions.size() > MAX_DEFINITIONS) throw new IllegalArgumentException("content limit exceeded (256)");
var ids = new HashSet<String>();
long characters = 0;
for (ContentDefinition definition : definitions) {
if (!ids.add(definition.id())) throw new IllegalArgumentException("duplicate content id: " + definition.id());
characters += definition.id().length() + definition.name().length() + definition.description().length();
characters += definition.properties().entrySet().stream().mapToLong(e -> e.getKey().length() + e.getValue().length()).sum();
for (var behavior : definition.behaviors()) {
characters += behavior.id().length() + behavior.event().length() + behavior.action().length();
characters += behavior.parameters().entrySet().stream().mapToLong(e -> e.getKey().length() + e.getValue().length()).sum();
}
}
if (characters > MAX_TEXT_CHARACTERS) throw new IllegalArgumentException("content workspace text budget exceeded");
Objects.requireNonNull(updatedAt, "content updatedAt");
updatedBy = ContentDefinition.text(updatedBy, "content actor", 1, 128);
}
}