From 90d28ee8a17d5682594cab4a4fc3cb9875b34202 Mon Sep 17 00:00:00 2001 From: usbharu Date: Sat, 9 Nov 2024 09:03:01 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Owl=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hideout-activitypub/build.gradle.kts | 6 ++++ .../hideout/activitypub/config/OwlConfig.kt | 29 +++++++++++++++++++ .../domain/shared/jobqueue/TaskPublisher.kt | 7 +++++ .../hideout/activitypub/domain/task/Task.kt | 15 ++++++++++ .../activitypub/domain/task/TaskBody.kt | 7 +++++ .../infrastructure/owl/OwlTaskPublisher.kt | 13 +++++++++ 6 files changed, 77 insertions(+) create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/config/OwlConfig.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/shared/jobqueue/TaskPublisher.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/task/Task.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/task/TaskBody.kt create mode 100644 hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/owl/OwlTaskPublisher.kt diff --git a/hideout-activitypub/build.gradle.kts b/hideout-activitypub/build.gradle.kts index 33dd538f..0694c0d5 100644 --- a/hideout-activitypub/build.gradle.kts +++ b/hideout-activitypub/build.gradle.kts @@ -17,6 +17,9 @@ version = "1.0-SNAPSHOT" repositories { mavenCentral() + maven { + url = uri("https://git.usbharu.dev/api/packages/usbharu/maven") + } } dependencies { @@ -26,6 +29,9 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-security") implementation(libs.bundles.jackson) + implementation(libs.owl.producer.api) + implementation(libs.owl.producer.embedded) + implementation(libs.owl.common.serialize.jackson) } tasks.test { diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/config/OwlConfig.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/config/OwlConfig.kt new file mode 100644 index 00000000..615be159 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/config/OwlConfig.kt @@ -0,0 +1,29 @@ +package dev.usbharu.hideout.activitypub.config + +import com.fasterxml.jackson.databind.ObjectMapper +import dev.usbharu.owl.common.property.* +import dev.usbharu.owl.producer.api.OWL +import dev.usbharu.owl.producer.api.OwlProducer +import dev.usbharu.owl.producer.embedded.EMBEDDED +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class OwlConfig { + @Bean + fun owlProducer(objectMapper: ObjectMapper): OwlProducer { + return OWL(EMBEDDED) { + this.propertySerializerFactory = CustomPropertySerializerFactory( + setOf( + IntegerPropertySerializer(), + StringPropertyValueSerializer(), + DoublePropertySerializer(), + BooleanPropertySerializer(), + LongPropertySerializer(), + FloatPropertySerializer(), + ObjectPropertySerializer(objectMapper), + ) + ) + } + } +} \ No newline at end of file diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/shared/jobqueue/TaskPublisher.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/shared/jobqueue/TaskPublisher.kt new file mode 100644 index 00000000..1c0c33b4 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/shared/jobqueue/TaskPublisher.kt @@ -0,0 +1,7 @@ +package dev.usbharu.hideout.activitypub.domain.shared.jobqueue + +import dev.usbharu.hideout.activitypub.domain.task.Task + +interface TaskPublisher { + suspend fun publish(task: Task<*>) +} \ No newline at end of file diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/task/Task.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/task/Task.kt new file mode 100644 index 00000000..77ab78c7 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/task/Task.kt @@ -0,0 +1,15 @@ +package dev.usbharu.hideout.activitypub.domain.task + +import dev.usbharu.hideout.core.domain.model.support.domain.Domain +import dev.usbharu.owl.common.task.Task +import java.time.Instant + +class Task( + val id: String, + val name: String, + val publishedOn: Instant, + val body: T, + val domain: Domain +) : Task() { + +} \ No newline at end of file diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/task/TaskBody.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/task/TaskBody.kt new file mode 100644 index 00000000..c0049b1d --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/task/TaskBody.kt @@ -0,0 +1,7 @@ +package dev.usbharu.hideout.activitypub.domain.task + +import dev.usbharu.hideout.core.domain.model.support.principal.Principal + +abstract class TaskBody(private val map: Map, val principal: Principal) { + fun toMap(): Map = map +} \ No newline at end of file diff --git a/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/owl/OwlTaskPublisher.kt b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/owl/OwlTaskPublisher.kt new file mode 100644 index 00000000..a641d786 --- /dev/null +++ b/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/owl/OwlTaskPublisher.kt @@ -0,0 +1,13 @@ +package dev.usbharu.hideout.activitypub.infrastructure.owl + +import dev.usbharu.hideout.activitypub.domain.shared.jobqueue.TaskPublisher +import dev.usbharu.hideout.activitypub.domain.task.Task +import dev.usbharu.owl.producer.api.OwlProducer +import org.springframework.stereotype.Service + +@Service +class OwlTaskPublisher(private val owlProducer: OwlProducer) : TaskPublisher { + override suspend fun publish(task: Task<*>) { + owlProducer.publishTask(task) + } +} \ No newline at end of file