Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve most compiler warnings and other maven warnings #100

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eco-application/eco-application-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<mainClass>community.flock.eco.application.example.ApplicationKt</mainClass>
</configuration>
Expand Down
22 changes: 1 addition & 21 deletions eco-application/eco-application-multi_tenant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<mainClass>community.flock.eco.application.multi_tenant.ApplicationKt</mainClass>
</configuration>
Expand All @@ -109,27 +110,6 @@
<target>${java.version}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>process-resources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/kotlin</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion eco-core/src/main/kotlin/extentions/PageableExtention.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.springframework.data.domain.Sort
fun Pageable?.consume(): PageRequest =
when {
this != null && sort == null -> PageRequest.of(page ?: 1, size ?: 10)
this != null && sort != null -> PageRequest.of(page ?: 1, size ?: 10, sort?.direction.consume(), sort?.order)
this != null && sort != null -> PageRequest.of(page ?: 1, size ?: 10, sort.direction.consume(), sort.order)
else -> PageRequest.of(0, 10)
}

Expand Down
12 changes: 6 additions & 6 deletions eco-core/src/main/kotlin/model/AbstractCodeEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ abstract class AbstractCodeEntity(
return Objects.hashCode(code)
}

override fun equals(obj: Any?): Boolean {
if (this === obj) return true
if (obj == null) return false
if (javaClass != obj.javaClass) return false
val other = obj as AbstractCodeEntity
return Objects.equals(code, other.code)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null) return false
if (javaClass != other.javaClass) return false
val otherAbstractCodeEntity = other as AbstractCodeEntity
return Objects.equals(code, otherAbstractCodeEntity.code)
}
}
12 changes: 6 additions & 6 deletions eco-core/src/main/kotlin/model/AbstractEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ abstract class AbstractEntity<ID : Serializable>(
return 13
}

override fun equals(obj: Any?): Boolean {
if (this === obj) return true
if (obj == null) return false
if (javaClass != obj.javaClass) return false
val other = obj as AbstractEntity<*>
return id != 0L && id == other.id
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null) return false
if (javaClass != other.javaClass) return false
val otherAbstractEntity = other as AbstractEntity<*>
return (id != 0L) && (id == otherAbstractEntity.id)
}

override fun toString() = "Entity of type ${this.javaClass.name} with id: $id"
Expand Down
12 changes: 6 additions & 6 deletions eco-core/src/main/kotlin/model/AbstractIdEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ abstract class AbstractIdEntity(
return 13
}

override fun equals(obj: Any?): Boolean {
if (this === obj) return true
if (obj == null) return false
if (javaClass != obj.javaClass) return false
val other = obj as AbstractIdEntity
return id != 0L && id == other.id
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null) return false
if (javaClass != other.javaClass) return false
val otherEntity = other as AbstractIdEntity
return id != 0L && id == otherEntity.id
}

override fun toString() = "Entity of type ${this.javaClass.name} with id: $id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Component
import org.springframework.web.client.HttpClientErrorException
import org.springframework.web.client.RestTemplate
Expand Down Expand Up @@ -65,17 +66,17 @@ class MailchimpClient(
try {
val entity = HttpEntity<String>(headers)
val res = restTemplate.exchange("/templates", HttpMethod.GET, entity, ObjectNode::class.java)
return res.body.get("templates").asIterable()
.map {
return res.body?.get("templates")?.asIterable()
?.map {
MailchimpTemplate(
id = it.get("id").asText(),
name = it.get("name").asText(),
type =
it.get("type").asText().let {
MailchimpTemplateType.valueOf(it.toUpperCase())
MailchimpTemplateType.valueOf(it.uppercase())
},
)
}
} ?: error("Could not retrieve mailchimp template")
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -91,8 +92,9 @@ class MailchimpClient(
entity,
ObjectNode::class.java,
)
return res.body.get("categories").asIterable()
.map { convertObjectNodeToMailchimpInterestCategory(it) }
return res.body?.get("categories")?.asIterable()
?.map { convertObjectNodeToMailchimpInterestCategory(it) }
?: error("Could not retrieve getInterestsCategories")
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -104,7 +106,8 @@ class MailchimpClient(
): MailchimpInterestCategory? {
val json = mapper.createObjectNode()
json.put("title", interestCategory.title)
json.put("type", interestCategory.type.toString().toLowerCase())

json.put("type", interestCategory.type.toString().lowercase())
val entity = HttpEntity(json, headers)
try {
val res =
Expand All @@ -114,7 +117,7 @@ class MailchimpClient(
entity,
ObjectNode::class.java,
)
return convertObjectNodeToMailchimpInterestCategory(res.body)
return res.body?.let { convertObjectNodeToMailchimpInterestCategory(it) }
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -133,8 +136,9 @@ class MailchimpClient(
entity,
ObjectNode::class.java,
)
return res.body.get("interests").asIterable()
.map { convertObjectNodeToMailchimpInterest(it) }
return res.body?.get("interests")?.asIterable()
?.map { convertObjectNodeToMailchimpInterest(it) }
?: error("Could not retrieve getInterests")
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -156,7 +160,9 @@ class MailchimpClient(
entity,
ObjectNode::class.java,
)
return convertObjectNodeToMailchimpInterest(res.body)
return convertObjectNodeToMailchimpInterest(
res.body ?: error("Could not post interests for list $listId, category id $interestCategoryId"),
)
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -166,14 +172,15 @@ class MailchimpClient(
try {
val entity = HttpEntity<String>(headers)
val res = restTemplate.exchange("/campaigns", HttpMethod.GET, entity, ObjectNode::class.java)
return res.body.get("campaigns").asIterable()
.map {
return res.body?.get("campaigns")?.asIterable()
?.map {
MailchimpCampaign(
id = it.get("id").asText(),
webId = it.get("web_id").asText(),
name = it.get("settings").get("title").asText(),
)
}
?: error("Could not retrieve campaigns")
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -185,8 +192,9 @@ class MailchimpClient(
val entity = HttpEntity<String>(headers)
val res =
restTemplate.exchange("/lists?offset=$offset&count=10", HttpMethod.GET, entity, ObjectNode::class.java)
val total = res.body.get("total_items").asLong()
return res.body.get("lists").asIterable()
val body = res.body ?: error("Could not retrieve lists")
val total = body.get("total_items").asLong()
return body.get("lists").asIterable()
.map(this::convertObjectNodetoMailchimpList)
.let { PageImpl(it, page, total) }
} catch (ex: HttpClientErrorException) {
Expand All @@ -202,15 +210,16 @@ class MailchimpClient(
val count = page.pageSize
try {
val entity = HttpEntity<String>(headers)
val res =
val res: ResponseEntity<ObjectNode> =
restTemplate.exchange(
"/lists/$listId/members?offset=$offset&count=$count",
HttpMethod.GET,
entity,
ObjectNode::class.java,
)
val total = res.body.get("total_items").asLong()
return res.body.get("members").asIterable()
val body = res.body ?: error("Could not retrieve getMembers")
val total = body.get("total_items").asLong()
return body.get("members").asIterable()
.map(this::convertObjectNodeToMailchimpMember)
.let { PageImpl(it, page, total) }
} catch (ex: HttpClientErrorException) {
Expand All @@ -227,7 +236,7 @@ class MailchimpClient(
try {
val res =
restTemplate.exchange("/lists/$listId/members/$md5", HttpMethod.GET, entity, ObjectNode::class.java)
return convertObjectNodeToMailchimpMember(res.body)
return convertObjectNodeToMailchimpMember(res.body ?: error("Could not retrieve member $email from list $listId"))
} catch (ex: HttpClientErrorException) {
if (ex.statusCode == HttpStatus.NOT_FOUND) {
return null
Expand All @@ -244,7 +253,7 @@ class MailchimpClient(
val entity = HttpEntity(obj, headers)
try {
val res = restTemplate.exchange("/lists/$listId/members", HttpMethod.POST, entity, ObjectNode::class.java)
return convertObjectNodeToMailchimpMember(res.body)
return convertObjectNodeToMailchimpMember(res.body ?: error("Could not post member ${member.email} to list $listId"))
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -260,7 +269,7 @@ class MailchimpClient(
try {
val res =
restTemplate.exchange("/lists/$listId/members/$md5", HttpMethod.PUT, entity, ObjectNode::class.java)
return convertObjectNodeToMailchimpMember(res.body)
return convertObjectNodeToMailchimpMember(res.body ?: error("Could not put member ${member.email} from list $listId"))
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -279,7 +288,7 @@ class MailchimpClient(
.map(this::convertMailchimpMembertoObjectNode),
)
val entity = HttpEntity(body, headers)
val res = restTemplate.exchange("/lists/$listId", HttpMethod.POST, entity, ObjectNode::class.java)
restTemplate.exchange("/lists/$listId", HttpMethod.POST, entity, ObjectNode::class.java)
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -295,7 +304,7 @@ class MailchimpClient(
body.putArray("static_segment")
val entity = HttpEntity(body, headers)
val res = restTemplate.exchange("/lists/$listId/segments", HttpMethod.POST, entity, ObjectNode::class.java)
return res.body.get("name").asText()
return res.body?.get("name")?.asText() ?: error("Could not retrieve segment")
} catch (ex: HttpClientErrorException) {
val res = mapper.readTree(ex.responseBodyAsString)
val detail = res.get("detail").asText()
Expand Down Expand Up @@ -332,13 +341,12 @@ class MailchimpClient(
}
val entity = HttpEntity(body, headers)
try {
val res =
restTemplate.exchange(
"/lists/$listId/members/$md5/tags",
HttpMethod.POST,
entity,
ObjectNode::class.java,
)
restTemplate.exchange(
"/lists/$listId/members/$md5/tags",
HttpMethod.POST,
entity,
ObjectNode::class.java,
)
} catch (ex: HttpClientErrorException) {
throw MailchimpFetchException(ex.responseBodyAsString)
}
Expand All @@ -349,17 +357,17 @@ class MailchimpClient(
MessageDigest.getInstance("MD5")
.digest(
email
.toLowerCase()
.lowercase()
.toByteArray(),
)
val md5 = DatatypeConverter.printHexBinary(digest)
return md5.toLowerCase()
return md5.lowercase()
}

private fun convertMailchimpMembertoObjectNode(member: MailchimpMember): ObjectNode {
val json = mapper.createObjectNode()
json.put("email_address", member.email)
json.put("status", member.status.toString().toLowerCase())
json.put("status", member.status.toString().lowercase())
json.put("language", member.language ?: "")
json.putPOJO("tags", member.tags)
json.putPOJO("interests", mapper.valueToTree(member.interests))
Expand All @@ -374,7 +382,7 @@ class MailchimpClient(
title = it.get("title").asText(),
type =
it.get("type").asText().let {
MailchimpInterestCategoryType.valueOf(it.toUpperCase())
MailchimpInterestCategoryType.valueOf(it.uppercase())
},
)

Expand Down Expand Up @@ -406,7 +414,7 @@ class MailchimpClient(
status =
obj.get("status")
?.asText()
?.let { MailchimpMemberStatus.valueOf(it.toUpperCase()) }
?.let { MailchimpMemberStatus.valueOf(it.uppercase()) }
?: MailchimpMemberStatus.UNSUBSCRIBED,
tags =
obj.get("tags")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ class MailchimpController(
val event =
MailchimpWebhookEvent(
type =
formData.getFirst("type")
.let { it.toUpperCase() }
formData.getFirst("type")!!.uppercase()
.let { MailchimpWebhookEventType.valueOf(it) },
firedAt =
formData.getFirst("fired_at")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class MemberQueryResolver(
sort: String?,
order: String?,
): PageRequest {
val order = order?.let { Sort.Direction.fromString(it) } ?: Sort.DEFAULT_DIRECTION
val sort = sort?.let { Sort.by(order, sort) } ?: Sort.unsorted()
return PageRequest.of(page ?: 0, size ?: 10, sort)
val resolvedDirection = order?.let { Sort.Direction.fromString(it) } ?: Sort.DEFAULT_DIRECTION
val resolvedSort = sort?.let { Sort.by(resolvedDirection, sort) } ?: Sort.unsorted()
return PageRequest.of(page ?: 0, size ?: 10, resolvedSort)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class MemberSpecification(
val searchCriteria =
if (search.isNotBlank()) {
cb.or(
cb.like(cb.lower(root.get("firstName")), "%${search.toLowerCase()}%"),
cb.like(cb.lower(root.get("surName")), "%${search.toLowerCase()}%"),
cb.like(cb.lower(root.get("email")), "%${search.toLowerCase()}%"),
cb.like(cb.lower(root.get("firstName")), "%${search.lowercase()}%"),
cb.like(cb.lower(root.get("surName")), "%${search.lowercase()}%"),
cb.like(cb.lower(root.get("email")), "%${search.lowercase()}%"),
)
} else {
cb.conjunction()
Expand Down
Loading
Loading