Add PushMessageProvider service and configuration
This commit is contained in:
parent
9c655b89e2
commit
1283c89615
|
|
@ -0,0 +1,59 @@
|
|||
package ru.touchin.push.message.provider.hpk.configurations
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
|
||||
import org.springframework.cache.CacheManager
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache
|
||||
import org.springframework.cache.support.SimpleCacheManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Import
|
||||
import ru.touchin.push.message.provider.configurations.PushMessageProviderConfiguration
|
||||
import ru.touchin.push.message.provider.hpk.services.HmsOauthAccessTokenCacheServiceImpl.Companion.HMS_CLIENT_SERVICE_CACHE_KEY
|
||||
|
||||
@ComponentScan("ru.touchin.push.message.provider.hpk")
|
||||
@ConfigurationPropertiesScan(basePackages = ["ru.touchin.push.message.provider.hpk"])
|
||||
@Import(value = [PushMessageProviderConfiguration::class])
|
||||
class PushMessageProviderHpkConfiguration {
|
||||
|
||||
@Bean
|
||||
@Qualifier("push-message-provider.hpk.webclient-objectmapper")
|
||||
fun webclientObjectMapper(): ObjectMapper {
|
||||
return jacksonObjectMapper()
|
||||
.registerModule(JavaTimeModule())
|
||||
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Qualifier("push-message-provider.hpk.client-objectmapper")
|
||||
fun clientObjectMapper(): ObjectMapper {
|
||||
return jacksonObjectMapper()
|
||||
.registerModule(JavaTimeModule())
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@Qualifier("push-message-provider.hpk.webclient-cachemanager")
|
||||
fun cacheManager(): CacheManager {
|
||||
return SimpleCacheManager().also {
|
||||
it.setCaches(
|
||||
listOf(
|
||||
ConcurrentMapCache(HMS_CLIENT_SERVICE_CACHE_KEY)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package ru.touchin.push.message.provider.hpk.services
|
||||
|
||||
import org.springframework.stereotype.Service
|
||||
import ru.touchin.push.message.provider.dto.request.PushTokenCheck
|
||||
import ru.touchin.push.message.provider.dto.request.PushTokenMessage
|
||||
import ru.touchin.push.message.provider.dto.request.SendPushRequest
|
||||
import ru.touchin.push.message.provider.dto.result.CheckPushTokenResult
|
||||
import ru.touchin.push.message.provider.dto.result.SendPushResult
|
||||
import ru.touchin.push.message.provider.dto.result.SendPushTokenMessageResult
|
||||
import ru.touchin.push.message.provider.enums.PushMessageProviderType
|
||||
import ru.touchin.push.message.provider.exceptions.InvalidPushTokenException
|
||||
import ru.touchin.push.message.provider.exceptions.PushMessageProviderException
|
||||
import ru.touchin.push.message.provider.services.PushMessageProviderService
|
||||
|
||||
@Service
|
||||
class PushMessageProviderHpkService(
|
||||
private val hmsHpkClientService: HmsHpkClientService,
|
||||
) : PushMessageProviderService {
|
||||
|
||||
override val type: PushMessageProviderType = PushMessageProviderType.HPK
|
||||
|
||||
@Throws(PushMessageProviderException::class, InvalidPushTokenException::class)
|
||||
override fun send(request: SendPushRequest): SendPushResult {
|
||||
when (request) {
|
||||
is PushTokenMessage -> hmsHpkClientService.send(request)
|
||||
}
|
||||
|
||||
return SendPushTokenMessageResult
|
||||
}
|
||||
|
||||
override fun check(request: PushTokenCheck): CheckPushTokenResult {
|
||||
val result = hmsHpkClientService.check(request)
|
||||
|
||||
return CheckPushTokenResult(result)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue