mirror of https://github.com/usbharu/Hideout.git
feat: ActivityPubの処理共通interfaceを追加
This commit is contained in:
parent
9540e8809d
commit
2dbbed9a5a
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
)
|
||||
}
|
|
@ -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)
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue