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 +}