Skip to content

Refactor AppServer to Kotlin#518

Open
this-Aditya wants to merge 147 commits intodevfrom
kotlin-refactor
Open

Refactor AppServer to Kotlin#518
this-Aditya wants to merge 147 commits intodevfrom
kotlin-refactor

Conversation

@this-Aditya
Copy link
Member

Refactor AppServer to Kotlin

Solves: #332

@this-Aditya this-Aditya marked this pull request as draft January 11, 2025 18:55
@this-Aditya this-Aditya force-pushed the kotlin-refactor branch 2 times, most recently from 98af8a8 to 453cf3a Compare January 13, 2025 14:53
@this-Aditya this-Aditya marked this pull request as ready for review January 18, 2025 12:49
Copy link
Member

@yatharthranjan yatharthranjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Half-way through the review, please find the comments for half

}

kapt {
keepJavacAnnotationProcessors = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which annotations is this for? can you check if there support for kapt from other equivalent libs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spring-context-indexer dependency, annotationProcessor "org.springframework:spring-context-indexer:$springVersion", was used for the mixed Java-Kotlin codebase. I'll remove this configuration.

}

jar {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which deps are duplicated? Might be good to add a resolution strategy

Copy link
Member Author

@this-Aditya this-Aditya Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file spring-configuration-metadata.json exists in two locations: one generated by KAPT and the other copied from the main resource directory, which ends up in the build location:

radar-appserver/build/tmp/kapt3/classes/main/META-INF/spring-configuration-metadata.json

radar-appserver/build/resources/main/META-INF/spring-configuration-metadata.json

The contents of both files are different. I created a custom task to read the content of the duplicate files, and the results are in the attached file

duplicates.txt

hibernateValidatorVersion = '8.0.0.Final'
minioVersion = '8.5.10'
kotlinVersion = '1.9.25'
jacksonKotlinVersion = '2.15.4'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer moving to kotlinx serialisation instead of jackson

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, both the appserver and Jersey use Jackson. Once I complete the Jersey work, I'll migrate from Jackson to Kotlinx Serialization by next week.


//Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonKotlinVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed when moving to kotlinx with json contentNegotiation

implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation "io.ktor:ktor-client-cio:$ktorVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we moving to mockk instead of mockito ?

Copy link
Member Author

@this-Aditya this-Aditya Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when writing the unit test for jersey I'll create the test cases using mockk.


@JsonIgnoreProperties(ignoreUnknown = true)
data class DataMessageStateEventDto (
var id: Long? = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason all of these are var. Avoid vars where possible, especially in a data contract/interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for all other DTOs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since JPA doesn't encourage the use of data classes with val fields, I kept the fields as var and nullable in DTOs. This way, they can be easily mapped without needing strict null checks (!!) for every field.

For more information on not using data classes and val fields with JPA: Medium - A practical point of view on Kotlin data classes and JPA/Hibernate.


@field:NotNull
@field:NotEmpty
var projectId: String? = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this non-nullable and remove the annotation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as above.

class FcmDataMessages {

@field:Size(max = 200)
private var _dataMessages: MutableList<FcmDataMessageDto> = mutableListOf()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use val here and have a constructor for setting dataMessages instead of fun withDataMessages

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll update this.

@Suppress("unused")
@JsonIgnoreProperties(ignoreUnknown = true)
class FcmDataMessageDto(dataMessageEntity: DataMessage? = null) : Serializable {
var id: Long? = dataMessageEntity?.id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use val with constructors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason for using var fields as mentioned in the above comment.

@Suppress("unused")
@JsonIgnoreProperties(ignoreUnknown = true)
class FcmNotificationDto(notificationEntity: Notification? = null) : Serializable {
var id: Long? = notificationEntity?.id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar you can use val with constructors instead of with... If you need to update the properties of the object somewhere, you can make a copy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll update this.

@yatharthranjan yatharthranjan mentioned this pull request Aug 7, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants