-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split common module into several smaller modules (!1135)
- Loading branch information
1 parent
1475a91
commit 79393a2
Showing
95 changed files
with
309 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// JVM Test Suite is still incubating, but expected to be stable soon, so disabling the warning. | ||
@file:Suppress("UnstableApiUsage") | ||
|
||
plugins { | ||
id("org.orkg.gradle.kotlin-library") | ||
} | ||
|
||
dependencies { | ||
api("org.eclipse.rdf4j:rdf4j-common-io") // for RFC 3987 compliant IRIs | ||
implementation(project(":common:string-utils")) | ||
} | ||
|
||
testing { | ||
suites { | ||
val test by getting(JvmTestSuite::class) { | ||
dependencies { | ||
implementation("io.kotest:kotest-assertions-shared") | ||
implementation("org.junit.jupiter:junit-jupiter-params") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
id("org.orkg.gradle.kotlin-library") | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
id("org.orkg.gradle.kotlin-library") | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
id("org.orkg.gradle.input-adapter-spring-web") // for RestDocs configuration | ||
id("org.orkg.gradle.kotlin-library") | ||
} | ||
|
||
dependencies { | ||
api("org.springframework.data:spring-data-commons") | ||
} | ||
|
||
testing { | ||
suites { | ||
val test by getting(JvmTestSuite::class) { | ||
dependencies { | ||
implementation(testFixtures(project(":testing:spring"))) | ||
implementation("org.junit.jupiter:junit-jupiter-api") | ||
implementation("org.springframework.boot:spring-boot-test") | ||
implementation("org.springframework.boot:spring-boot-test-autoconfigure") | ||
implementation("org.springframework.restdocs:spring-restdocs-core") | ||
implementation("org.springframework:spring-test") | ||
implementation("org.springframework:spring-web") | ||
implementation("org.springframework.restdocs:spring-restdocs-mockmvc") | ||
runtimeOnly("com.jayway.jsonpath:json-path") | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
common/spring-webmvc/src/main/kotlin/org/orkg/common/WebExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.orkg.common | ||
|
||
import java.io.IOException | ||
import java.net.http.HttpClient | ||
import java.net.http.HttpRequest | ||
import java.net.http.HttpResponse | ||
import java.time.Duration | ||
import org.orkg.common.exceptions.ServiceUnavailable | ||
import org.springframework.http.CacheControl | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ResponseEntity | ||
|
||
fun <T> T.withCacheControl(duration: Duration): ResponseEntity<T> = | ||
ResponseEntity.ok().cacheControl(CacheControl.maxAge(duration)).body(this) | ||
|
||
fun <T> HttpClient.send(httpRequest: HttpRequest, serviceName: String, successCallback: (String) -> T): T? { | ||
try { | ||
val response = send(httpRequest, HttpResponse.BodyHandlers.ofString()) | ||
return when (response.statusCode()) { | ||
HttpStatus.OK.value() -> successCallback(response.body()) | ||
HttpStatus.NOT_FOUND.value() -> null | ||
else -> throw ServiceUnavailable.create(serviceName, response.statusCode(), response.body()) | ||
} | ||
} catch (e: IOException) { | ||
throw ServiceUnavailable.create(serviceName, e) | ||
} | ||
} |
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
...g-webmvc/src/main/kotlin/org/orkg/common/configuration/PagedSerializationConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.orkg.common.configuration | ||
|
||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.web.config.EnableSpringDataWebSupport | ||
|
||
@Configuration | ||
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.DIRECT) | ||
class PagedSerializationConfiguration |
18 changes: 18 additions & 0 deletions
18
common/spring-webmvc/src/main/kotlin/org/orkg/common/configuration/WebMvcConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.orkg.common.configuration | ||
|
||
import org.orkg.common.MediaTypeCapabilitiesResolver | ||
import org.orkg.common.MediaTypeCapabilityRegistry | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Import | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer | ||
|
||
@Configuration | ||
@Import(MediaTypeCapabilityRegistry::class) | ||
class WebMvcConfiguration( | ||
private val mediaTypeCapabilityRegistry: MediaTypeCapabilityRegistry, | ||
) : WebMvcConfigurer { | ||
override fun addArgumentResolvers(resolvers: MutableList<HandlerMethodArgumentResolver>) { | ||
resolvers.add(MediaTypeCapabilitiesResolver(mediaTypeCapabilityRegistry)) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 0 additions & 27 deletions
27
common/src/test/kotlin/org/orkg/common/TimeEqualsContractTest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// JVM Test Suite is still incubating, but expected to be stable soon, so disabling the warning. | ||
@file:Suppress("UnstableApiUsage") | ||
|
||
plugins { | ||
id("org.orkg.gradle.kotlin-library") | ||
} | ||
|
||
testing { | ||
suites { | ||
val test by getting(JvmTestSuite::class) { | ||
dependencies { | ||
implementation("org.junit.jupiter:junit-jupiter-api") | ||
implementation("org.assertj:assertj-core") | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
common/string-utils/src/main/kotlin/org/orkg/common/StringExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.orkg.common | ||
|
||
import java.math.BigInteger | ||
import java.security.MessageDigest | ||
|
||
fun String.toSnakeCase(): String = | ||
if (this.isEmpty()) this else StringBuilder().also { | ||
this.forEach { c -> | ||
when (c) { | ||
in 'A'..'Z' -> { | ||
it.append("_") | ||
it.append(c.lowercase()) | ||
} | ||
|
||
else -> { | ||
it.append(c) | ||
} | ||
} | ||
} | ||
}.toString() | ||
|
||
/** | ||
* Calculate the MD5 of a string. | ||
* | ||
* @return The MD5 in hexadecimal, zero-prefixed to 32 characters. | ||
*/ | ||
val String.md5: String | ||
get() = BigInteger(1, MessageDigest.getInstance("MD5").digest(this.toByteArray())) | ||
.toString(16) | ||
.padStart(32, '0') |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.