Skip to content

Commit

Permalink
fix: ObjectMapperConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter committed Dec 10, 2024
1 parent f5fa229 commit 52d21c3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.aamdigital.aambackendservice.skill.domain.EscoSkill
import com.aamdigital.aambackendservice.skill.domain.SkillUsage
import com.aamdigital.aambackendservice.skill.domain.UserProfile
import com.aamdigital.aambackendservice.skill.repository.SkillLabUserProfileRepository
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
Expand Down Expand Up @@ -41,6 +42,7 @@ data class FetchUserProfilesDto(
class SkillController(
private val searchUserProfileUseCase: SearchUserProfileUseCase,
private val userProfileRepository: SkillLabUserProfileRepository,
private val objectMapper: ObjectMapper,
) {

companion object {
Expand Down Expand Up @@ -131,7 +133,7 @@ class SkillController(
email = entity.email,
skills = entity.skills.map {
EscoSkill(
usage = SkillUsage.valueOf(it.usage.uppercase()),
usage = objectMapper.convertValue(it.usage.uppercase(), SkillUsage::class.java),
escoUri = it.escoUri
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.aamdigital.aambackendservice.skill.domain.SkillUsage
import com.aamdigital.aambackendservice.skill.domain.UserProfile
import com.aamdigital.aambackendservice.skill.repository.SkillLabUserProfileEntity
import com.aamdigital.aambackendservice.skill.repository.SkillLabUserProfileRepository
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.data.domain.Example
import org.springframework.data.domain.ExampleMatcher
import org.springframework.data.domain.Page
Expand All @@ -24,6 +25,7 @@ import org.springframework.data.domain.Pageable
*/
class SqlSearchUserProfileUseCase(
private val userProfileRepository: SkillLabUserProfileRepository,
private val objectMapper: ObjectMapper,
) : SearchUserProfileUseCase() {

companion object {
Expand Down Expand Up @@ -170,7 +172,7 @@ class SqlSearchUserProfileUseCase(
phone = it.mobileNumber,
skills = it.skills.map { skill ->
EscoSkill(
usage = SkillUsage.valueOf(skill.usage.uppercase()),
usage = objectMapper.convertValue(skill.usage.uppercase(), SkillUsage::class.java),
escoUri = skill.escoUri
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ class SkillConfigurationSkillLab {
fun skillLabSyncUserProfileUseCase(
skillLabClient: SkillLabClient,
skillLabUserProfileRepository: SkillLabUserProfileRepository,
objectMapper: ObjectMapper,
): SyncUserProfileUseCase = SkillLabSyncUserProfileUseCase(
skillLabClient = skillLabClient,
skillLabUserProfileRepository = skillLabUserProfileRepository,
objectMapper = objectMapper,
)

@Bean
fun sqlSearchUserProfileUseCase(
skillLabUserProfileRepository: SkillLabUserProfileRepository,
objectMapper: ObjectMapper,
): SearchUserProfileUseCase = SqlSearchUserProfileUseCase(
userProfileRepository = skillLabUserProfileRepository,
objectMapper = objectMapper,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.aamdigital.aambackendservice.skill.domain.UserProfile
import com.aamdigital.aambackendservice.skill.repository.SkillLabUserProfileEntity
import com.aamdigital.aambackendservice.skill.repository.SkillLabUserProfileRepository
import com.aamdigital.aambackendservice.skill.repository.SkillReferenceEntity
import com.fasterxml.jackson.databind.ObjectMapper

enum class SkillLabSyncUserProfileErrorCode : AamErrorCode {
IO_ERROR
Expand All @@ -22,6 +23,7 @@ enum class SkillLabSyncUserProfileErrorCode : AamErrorCode {
class SkillLabSyncUserProfileUseCase(
private val skillLabClient: SkillLabClient,
private val skillLabUserProfileRepository: SkillLabUserProfileRepository,
private val objectMapper: ObjectMapper,
) : SyncUserProfileUseCase() {

override fun apply(request: SyncUserProfileRequest): UseCaseOutcome<SyncUserProfileData> {
Expand Down Expand Up @@ -59,7 +61,7 @@ class SkillLabSyncUserProfileUseCase(
email = userProfileEntity.email,
skills = allSkillsEntities.map { skill ->
EscoSkill(
usage = SkillUsage.valueOf(skill.usage.uppercase()),
usage = objectMapper.convertValue(skill.usage.uppercase(), SkillUsage::class.java),
escoUri = skill.escoUri
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.springframework.data.domain.Example
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageImpl
import org.springframework.data.domain.Pageable
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import kotlin.test.assertEquals

@ExtendWith(MockitoExtension::class)
Expand All @@ -36,7 +37,10 @@ class SqlSearchUserProfileUseCaseTest {
@BeforeEach
fun setup() {
reset(userProfileRepository)
service = SqlSearchUserProfileUseCase(userProfileRepository = userProfileRepository)
service = SqlSearchUserProfileUseCase(
userProfileRepository = userProfileRepository,
objectMapper = Jackson2ObjectMapperBuilder().build()
)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.mockito.kotlin.reset
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import java.io.IOException
import java.util.*

Expand All @@ -39,7 +40,9 @@ class SkillLabSyncUserProfileUseCaseTest {
skillLabUserProfileRepository,
)
service = SkillLabSyncUserProfileUseCase(
skillLabClient = skillLabClient, skillLabUserProfileRepository = skillLabUserProfileRepository
skillLabClient = skillLabClient,
skillLabUserProfileRepository = skillLabUserProfileRepository,
objectMapper = Jackson2ObjectMapperBuilder().build(),
)
}

Expand Down

0 comments on commit 52d21c3

Please sign in to comment.