From c4481b237348eafb4f0b30f2621016796a2454d1 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Mon, 19 Apr 2021 23:24:28 +0200 Subject: [PATCH] ClearlyDefinedService: Support the API for curation bulk requests This is a preparation for resolving #3905. Signed-off-by: Sebastian Schuberth --- .../kotlin/ClearlyDefinedServiceFunTest.kt | 29 +++++++++++++++---- .../src/main/kotlin/ClearlyDefinedService.kt | 13 +++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/clients/clearly-defined/src/funTest/kotlin/ClearlyDefinedServiceFunTest.kt b/clients/clearly-defined/src/funTest/kotlin/ClearlyDefinedServiceFunTest.kt index 4a5fc59661465..e194d4774233e 100644 --- a/clients/clearly-defined/src/funTest/kotlin/ClearlyDefinedServiceFunTest.kt +++ b/clients/clearly-defined/src/funTest/kotlin/ClearlyDefinedServiceFunTest.kt @@ -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 { diff --git a/clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt b/clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt index 9f0c86445568a..9d916303d04a1 100644 --- a/clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt +++ b/clients/clearly-defined/src/main/kotlin/ClearlyDefinedService.kt @@ -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 @@ -152,6 +153,11 @@ interface ClearlyDefinedService { val files: List? = null ) + data class ContributedCurations( + val curations: Map, + val contributions: List + ) + /** * See https://github.com/clearlydefined/service/blob/4917725/schemas/definition-1.0.json#L145-L179. */ @@ -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): Map + /** * Upload curation [patch] data, see https://api.clearlydefined.io/api-docs/#/curations/patch_curations. */