Skip to content

Commit

Permalink
ClearlyDefinedService: Support the API for curation bulk requests
Browse files Browse the repository at this point in the history
This is a preparation for resolving #3905.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Apr 19, 2021
1 parent fb9186b commit c4481b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,36 @@ class ClearlyDefinedServiceFunTest : WordSpec({
}

"Downloading a contribution patch" should {
"return curation data".config(tags = setOf(ExpensiveTag)) {
val coordinates = Coordinates(
ComponentType.MAVEN,
Provider.MAVEN_CENTRAL,
"javax.servlet",
"javax.servlet-api",
"3.1.0"
)

"return single curation data".config(tags = setOf(ExpensiveTag)) {
val service = ClearlyDefinedService.create(Server.PRODUCTION)

val curation = service.getCuration(
ComponentType.MAVEN,
Provider.MAVEN_CENTRAL,
"javax.servlet",
"javax.servlet-api",
"3.1.0"
coordinates.type,
coordinates.provider,
coordinates.namespace.orEmpty(),
coordinates.name,
coordinates.revision.orEmpty()
)

curation.licensed?.declared shouldBe "CDDL-1.0 OR GPL-2.0-only WITH Classpath-exception-2.0"
}

"return bulk curation data".config(tags = setOf(ExpensiveTag)) {
val service = ClearlyDefinedService.create(Server.PRODUCTION)

val curations = service.getCurations(listOf(coordinates))
val curation = curations[coordinates]?.curations?.get(coordinates)

curation?.licensed?.declared shouldBe "CDDL-1.0 OR GPL-2.0-only WITH Classpath-exception-2.0"
}
}

"Uploading a contribution patch" should {
Expand Down
13 changes: 13 additions & 0 deletions clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonValue
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule

Expand Down Expand Up @@ -152,6 +153,11 @@ interface ClearlyDefinedService {
val files: List<FileEntry>? = null
)

data class ContributedCurations(
val curations: Map<Coordinates, Curation>,
val contributions: List<JsonNode>
)

/**
* See https://github.com/clearlydefined/service/blob/4917725/schemas/definition-1.0.json#L145-L179.
*/
Expand Down Expand Up @@ -439,6 +445,13 @@ interface ClearlyDefinedService {
@Path("revision") revision: String
): Curation

/**
* Return a batch of curations for the components given as [coordinates], see
* https://api.clearlydefined.io/api-docs/#/curations/post_curations_.
*/
@POST("curations")
suspend fun getCurations(@Body coordinates: Collection<Coordinates>): Map<Coordinates, ContributedCurations>

/**
* Upload curation [patch] data, see https://api.clearlydefined.io/api-docs/#/curations/patch_curations.
*/
Expand Down

0 comments on commit c4481b2

Please sign in to comment.