From 2dbbed9a5a7206b762b5484801dea91db6dd3041 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 22 Nov 2023 00:56:12 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20ActivityPub=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E5=85=B1=E9=80=9Ainterface=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ActivityPubProcessException.kt | 21 +++++++++++++++ .../exception/FailedProcessException.kt | 14 ++++++++++ .../tmp/AbstractActivityPubProcessor.kt | 27 +++++++++++++++++++ .../service/tmp/ActivityPubProcessor.kt | 10 +++++++ 4 files changed, 72 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/ActivityPubProcessException.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/AbstractActivityPubProcessor.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/ActivityPubProcessor.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/ActivityPubProcessException.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/ActivityPubProcessException.kt new file mode 100644 index 00000000..c8cf6a0c --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/ActivityPubProcessException.kt @@ -0,0 +1,21 @@ +package dev.usbharu.hideout.activitypub.domain.exception + +import java.io.Serial + +class ActivityPubProcessException : RuntimeException { + constructor() : super() + constructor(message: String?) : super(message) + constructor(message: String?, cause: Throwable?) : super(message, cause) + constructor(cause: Throwable?) : super(cause) + constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super( + message, + cause, + enableSuppression, + writableStackTrace + ) + + companion object { + @Serial + private const val serialVersionUID: Long = 5370068873167636639L + } +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt new file mode 100644 index 00000000..31c4b47e --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/exception/FailedProcessException.kt @@ -0,0 +1,14 @@ +package dev.usbharu.hideout.activitypub.domain.exception + +class FailedProcessException : RuntimeException { + constructor() : super() + constructor(message: String?) : super(message) + constructor(message: String?, cause: Throwable?) : super(message, cause) + constructor(cause: Throwable?) : super(cause) + constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super( + message, + cause, + enableSuppression, + writableStackTrace + ) +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/AbstractActivityPubProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/AbstractActivityPubProcessor.kt new file mode 100644 index 00000000..ff23a65e --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/AbstractActivityPubProcessor.kt @@ -0,0 +1,27 @@ +package dev.usbharu.hideout.activitypub.service.tmp + +import dev.usbharu.hideout.activitypub.domain.exception.ActivityPubProcessException +import dev.usbharu.hideout.activitypub.domain.exception.FailedProcessException +import dev.usbharu.hideout.activitypub.domain.model.objects.Object +import dev.usbharu.hideout.application.external.Transaction +import org.slf4j.LoggerFactory + +abstract class AbstractActivityPubProcessor(val transaction: Transaction) : ActivityPubProcessor { + private val logger = LoggerFactory.getLogger(this::class.java) + + override suspend fun process(activity: T) { + logger.info("START ActivityPub process") + try { + transaction.transaction { + internalProcess(activity) + } + } catch (e: ActivityPubProcessException) { + logger.warn("FAILED ActivityPub process", e) + throw FailedProcessException("Failed process", e) + } + logger.info("SUCCESS ActivityPub process") + } + + abstract suspend fun internalProcess(activity: T) + +} diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/ActivityPubProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/ActivityPubProcessor.kt new file mode 100644 index 00000000..919bf836 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/ActivityPubProcessor.kt @@ -0,0 +1,10 @@ +package dev.usbharu.hideout.activitypub.service.tmp + +import dev.usbharu.hideout.activitypub.domain.model.objects.Object +import dev.usbharu.hideout.activitypub.service.common.ActivityType + +interface ActivityPubProcessor { + suspend fun process(activity: T) + + fun isSupported(activityType: ActivityType): Boolean +}