diff --git a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/Bot.java b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/Bot.java index 0267522..69a6f6a 100644 --- a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/Bot.java +++ b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/Bot.java @@ -2,86 +2,53 @@ package dev.activitypub.activitypubbot; import lombok.Getter; import lombok.Setter; -import jakarta.persistence.Entity; -import jakarta.persistence.EntityListeners; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import jakarta.persistence.Id; -import jakarta.persistence.Column; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import org.springframework.data.annotation.CreatedDate; +import lombok.AccessLevel; +import lombok.Data; import java.time.Instant; /** - * Our core Bot (aka user) data as stored persistently in the database. - * This is all the key non-derived data as required by the ActivityPub - * specification. NOTE: This is not a comprehensive implementation! + * POJO for our Bot... */ -@Entity -@EntityListeners(AuditingEntityListener.class) +@Data public class Bot { - @Id - @GeneratedValue(strategy=GenerationType.AUTO) - private Long id; + @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) + Long id; // does this even need to be exposed here? + String username; // "preferredUsername: springbot", + String name; // "Spring Bot", + String summary; // "
A bot written using Java/Spring
", - /////////////////////////////////////////////////////////////////////////// - // The next values are user-supplied + @Setter(AccessLevel.NONE) + Instant published; // "2025-01-24T00:00:00Z", - /** - * Username of the bot, i.e. the value after the @: @<username>@<domain> - * Note that in the Activity Pub spec this is encoded as 'preferredUsername', - * we shorten just to username here for clarity and brevity in the code. - * - * @param username the username value - * @return the username value - */ - @Column(nullable=false,unique=true) - @Getter @Setter private String username; // "preferredUsername: springbot", - - /** - * The "friendly" formatted name of the bot, can have spaces, etc. - * - * @param name a presentational name for the bot - * @return the presentational name for the bot - */ - @Column(nullable=true,unique=false) - @Getter @Setter private String name; // "Spring Bot", - - /** - * A bit of text to describe the bot/account, an "about". - * - * @param summary Text describing the bot/account - * @return the summary string - */ - @Column(nullable=true,unique=false) - @Getter @Setter private String summary; // "A bot written using Java/Spring
", - - /////////////////////////////////////////////////////////////////////////// - // The following values will be auto-generated on bot-creation - - @CreatedDate // TODO: is this really the right approach to auto-timestamp, not sure about all this "auditing" stuff, feels like a misuse - @Getter private Instant published; // "2025-01-24T00:00:00Z", - - // TODO how and where do we generate this beastie?!?! - @Column(nullable=true,unique=false) // FIXME: this isn't true, just easy for now - @Getter private String publicKeyPem; // "-----BEGIN PUBLIC KEY-----\\nMI [...] AB\\n-----END PUBLIC KEY-----" + @Setter(AccessLevel.NONE) + String publicKeyPem; // "-----BEGIN PUBLIC KEY-----\\nMI [...] AB\\n-----END PUBLIC KEY-----" - /////////////////////////////////////////////////////////////////////////// - // These values can just be constants for the timebeing - - @Column(nullable=false,unique=false) - @Getter private static final String type = "Person"; + @Setter(AccessLevel.NONE) + String type = "Person"; - @Column(nullable=false,unique=false) - @Getter private static final boolean manuallyApproveFollowers = false; + @Setter(AccessLevel.NONE) + boolean manuallyApproveFollowers = false; - @Column(nullable=false,unique=false) - @Getter private static final boolean indexable = false; + @Setter(AccessLevel.NONE) + boolean indexable = false; @Override public String toString() { return "Bot: " + this.username; } + + Bot() { + } + Bot( String username, String name, String summary, String type, boolean manuallyApproveFollowers, boolean indexable, String pubicKeyPem ) { + this.username = username; + this.name = name; + this.summary = summary; + this.type = type; + this.manuallyApproveFollowers = manuallyApproveFollowers; + this.indexable = indexable; + this.publicKeyPem = publicKeyPem; + } } + diff --git a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/BotController.java b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/BotController.java index b0c7fc2..ec0d629 100644 --- a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/BotController.java +++ b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/BotController.java @@ -18,16 +18,13 @@ import lombok.extern.slf4j.Slf4j; public class BotController { @Autowired - private BotRepo botRepo; - - @Autowired - private BotService botService; + private BotService botServ; @GetMapping("/viewbot") public String listAll(Model model) { log.info("WebHandler::viewbot"); - ListA bot written using Java/Spring
", + + /////////////////////////////////////////////////////////////////////////// + // The following values will be auto-generated on bot-creation + + @CreatedDate // TODO: is this really the right approach to auto-timestamp, not sure about all this "auditing" stuff, feels like a misuse + @Getter private Instant published; // "2025-01-24T00:00:00Z", + + // TODO how and where do we generate this beastie?!?! + @Column(nullable=true,unique=false) // FIXME: this isn't true, just easy for now + @Getter private String publicKeyPem; // "-----BEGIN PUBLIC KEY-----\\nMI [...] AB\\n-----END PUBLIC KEY-----" + + @Column(nullable=false,unique=false) + @Getter private String type; + + @Column(nullable=false,unique=false) + @Getter private boolean manuallyApproveFollowers; + + @Column(nullable=false,unique=false) + @Getter private boolean indexable; + + static BotModel from(Bot bot) { + BotModel bm = new BotModel(); + bm.username = bot.getUsername(); + bm.name = bot.getName(); + bm.summary = bot.getSummary(); + bm.type = bot.getType(); + bm.manuallyApproveFollowers = bot.isManuallyApproveFollowers(); + bm.indexable = bot.isIndexable(); + bm.publicKeyPem = bot.getPublicKeyPem(); + return bm; + } + + Bot asBot() { + return new Bot( username, name, summary, type, manuallyApproveFollowers, indexable, publicKeyPem ); + } + + @Override + public String toString() { + return "Bot: " + this.username; + } + +} diff --git a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/BotRepo.java b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/BotRepo.java index 999ba05..aef8d5a 100644 --- a/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/BotRepo.java +++ b/Java/Spring/activitypubbot/src/main/java/dev/activitypub/activitypubbot/BotRepo.java @@ -1,10 +1,20 @@ package dev.activitypub.activitypubbot; -import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; +import java.util.List; /** - * Database shenanigans... + * Interface for a Bot respository. + * + * Working to the @Repository documentation and some other examples + * for this, a pattern noted to be "close to the DAO pattern". But I + * am not yet clear on the need/justification for this approach. */ -public interface BotRepo extends JpaRepository