feat: ActivityPubの処理共通interfaceを追加

This commit is contained in:
usbharu 2023-11-22 00:56:12 +09:00
parent 9540e8809d
commit 2dbbed9a5a
4 changed files with 72 additions and 0 deletions

View File

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

View File

@ -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
)
}

View File

@ -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<T : Object>(val transaction: Transaction) : ActivityPubProcessor<T> {
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)
}

View File

@ -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<T : Object> {
suspend fun process(activity: T)
fun isSupported(activityType: ActivityType): Boolean
}