diff --git a/backend/src/main/kotlin/dev/dres/api/rest/handler/download/EvaluationDownloadHandler.kt b/backend/src/main/kotlin/dev/dres/api/rest/handler/download/EvaluationDownloadHandler.kt index d881f49c..ec935beb 100644 --- a/backend/src/main/kotlin/dev/dres/api/rest/handler/download/EvaluationDownloadHandler.kt +++ b/backend/src/main/kotlin/dev/dres/api/rest/handler/download/EvaluationDownloadHandler.kt @@ -1,7 +1,7 @@ package dev.dres.api.rest.handler.download -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import dev.dres.api.rest.handler.GetRestHandler +import dev.dres.api.rest.types.evaluation.ApiEvaluation import dev.dres.api.rest.types.status.ErrorStatus import dev.dres.api.rest.types.status.ErrorStatusException import dev.dres.data.model.run.DbEvaluation @@ -18,7 +18,7 @@ import kotlinx.dnq.query.query * @author Ralph Gasser * @version 1.0.0 */ -class EvaluationDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler { +class EvaluationDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler { /** The route of this [EvaluationDownloadHandler]. */ override val route = "download/evaluation/{evaluationId}" @@ -32,14 +32,14 @@ class EvaluationDownloadHandler(private val store: TransientEntityStore) : Abstr OpenApiParam("evaluationId", String::class, "The evaluation ID.", required = true) ], responses = [ - OpenApiResponse("200", [OpenApiContent(String::class, type = "application/json")]), + OpenApiResponse("200", [OpenApiContent(ApiEvaluation::class)]), OpenApiResponse("400", [OpenApiContent(ErrorStatus::class)]), OpenApiResponse("401", [OpenApiContent(ErrorStatus::class)]), OpenApiResponse("404", [OpenApiContent(ErrorStatus::class)]) ], methods = [HttpMethod.GET] ) - override fun doGet(ctx: Context): String { + override fun doGet(ctx: Context): ApiEvaluation { /* Obtain run id and run. */ val evaluationId = ctx.pathParamMap().getOrElse("evaluationId") { throw ErrorStatusException(400, "Parameter 'evaluationId' is missing!'", ctx) } val evaluation = this.store.transactional(true) { @@ -51,7 +51,6 @@ class EvaluationDownloadHandler(private val store: TransientEntityStore) : Abstr ctx.header("Content-Disposition", "attachment; filename=\"run-${evaluationId}.json\"") /* Return value. */ - val mapper = jacksonObjectMapper() - return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(evaluation) + return evaluation } } diff --git a/backend/src/main/kotlin/dev/dres/api/rest/handler/download/EvaluationTemplateDownloadHandler.kt b/backend/src/main/kotlin/dev/dres/api/rest/handler/download/EvaluationTemplateDownloadHandler.kt index c222f7d0..28bb108b 100644 --- a/backend/src/main/kotlin/dev/dres/api/rest/handler/download/EvaluationTemplateDownloadHandler.kt +++ b/backend/src/main/kotlin/dev/dres/api/rest/handler/download/EvaluationTemplateDownloadHandler.kt @@ -4,6 +4,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import dev.dres.api.rest.handler.GetRestHandler import dev.dres.api.rest.types.status.ErrorStatus import dev.dres.api.rest.types.status.ErrorStatusException +import dev.dres.api.rest.types.template.ApiEvaluationTemplate import dev.dres.data.model.template.DbEvaluationTemplate import io.javalin.http.Context import io.javalin.openapi.* @@ -18,7 +19,8 @@ import kotlinx.dnq.query.query * @author Ralph Gasser * @version 1.0.0 */ -class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler { +class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), + GetRestHandler { /** The route of this [EvaluationTemplateDownloadHandler]. */ override val route = "download/template/{templateId}" @@ -39,7 +41,7 @@ class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore) ], methods = [HttpMethod.GET] ) - override fun doGet(ctx: Context): String { + override fun doGet(ctx: Context): ApiEvaluationTemplate { /* Obtain run id and run. */ val templateId = ctx.pathParamMap()["templateId"] ?: throw ErrorStatusException(400, "Parameter 'templateId' is missing!'", ctx) val template = this.store.transactional(true) { @@ -51,7 +53,6 @@ class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore) ctx.header("Content-Disposition", "attachment; filename=\"evaluation-template-${templateId}.json") /* Return value. */ - val mapper = jacksonObjectMapper() - return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(template) + return template } } diff --git a/backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/ApiTask.kt b/backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/ApiTask.kt index 031a9888..ad8500e1 100644 --- a/backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/ApiTask.kt +++ b/backend/src/main/kotlin/dev/dres/api/rest/types/evaluation/ApiTask.kt @@ -1,6 +1,8 @@ package dev.dres.api.rest.types.evaluation import dev.dres.api.rest.types.evaluation.submission.ApiAnswerSet +import dev.dres.api.rest.types.evaluation.submission.ApiClientSubmission +import dev.dres.api.rest.types.evaluation.submission.ApiSubmission import dev.dres.data.model.run.DbTask import dev.dres.data.model.run.TaskId import dev.dres.data.model.template.TemplateId @@ -19,5 +21,5 @@ data class ApiTask( val templateId: TemplateId, val started: Long?, val ended: Long?, - val submissions: List -) \ No newline at end of file + val submissions: List +) diff --git a/backend/src/main/kotlin/dev/dres/data/model/run/DbTask.kt b/backend/src/main/kotlin/dev/dres/data/model/run/DbTask.kt index c5b70370..69d3be52 100644 --- a/backend/src/main/kotlin/dev/dres/data/model/run/DbTask.kt +++ b/backend/src/main/kotlin/dev/dres/data/model/run/DbTask.kt @@ -1,6 +1,7 @@ package dev.dres.data.model.run import dev.dres.api.rest.types.evaluation.ApiTask +import dev.dres.api.rest.types.evaluation.submission.ApiClientSubmission import dev.dres.data.model.PersistentEntity import dev.dres.data.model.submissions.AnswerSet import dev.dres.data.model.template.task.DbTaskTemplate @@ -11,6 +12,7 @@ import dev.dres.data.model.template.team.DbTeam import jetbrains.exodus.entitystore.Entity import kotlinx.dnq.* import kotlinx.dnq.query.asSequence +import kotlinx.dnq.query.mapDistinct import kotlinx.dnq.util.isInstanceOf import java.lang.IllegalStateException @@ -47,9 +49,12 @@ class DbTask(entity: Entity) : PersistentEntity(entity) { /** Link to a [DbTeam] this [DbTask] was created for. Can be NULL!*/ var team by xdLink0_1(DbTeam) - /** List of [DbSubmission]s received by this [DbTask]. */ + /** List of [DbAnswerSet]s received by this [DbTask]. */ val answerSets by xdLink0_N(DbAnswerSet::task) + /** List of [DbSubmission]s received by this [DbTask].*/ + fun submissions() = this.answerSets.asSequence().map{it.submission}.toList() + /** * Converts this [DbTask] to a RESTful API representation [ApiTask]. * @@ -62,6 +67,6 @@ class DbTask(entity: Entity) : PersistentEntity(entity) { templateId = this.template.id, started = this.started, ended = this.ended, - submissions = this.answerSets.asSequence().map { it.toApi() }.toList() + submissions = submissions().map { it.toApi() }.toList() ) -} \ No newline at end of file +} diff --git a/doc/oas-client.json b/doc/oas-client.json index 37ca2dc6..e49851c2 100644 --- a/doc/oas-client.json +++ b/doc/oas-client.json @@ -2,8 +2,8 @@ "openapi" : "3.0.3", "info" : { "title" : "DRES Client API", - "version" : "2.0.0-RC5", - "description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0-RC5" + "version" : "2.0.0", + "description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0" }, "paths" : { "/api/v2/client/evaluation/currentTask/{evaluationId}" : { @@ -1342,7 +1342,7 @@ "submissions" : { "type" : "array", "items" : { - "$ref" : "#/components/schemas/ApiAnswerSet" + "$ref" : "#/components/schemas/ApiSubmission" } } }, diff --git a/doc/oas.json b/doc/oas.json index d62691e4..5bfc68ae 100644 --- a/doc/oas.json +++ b/doc/oas.json @@ -2,8 +2,8 @@ "openapi" : "3.0.3", "info" : { "title" : "DRES API", - "version" : "2.0.0-RC5", - "description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0-RC5", + "version" : "2.0.0", + "description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0", "contact" : { "name" : "The DRES Dev Team", "url" : "https://dres.dev" @@ -594,9 +594,9 @@ "200" : { "description" : "OK", "content" : { - "text/plain" : { + "application/json" : { "schema" : { - "type" : "string" + "$ref" : "#/components/schemas/ApiEvaluation" } } } @@ -5756,7 +5756,7 @@ "submissions" : { "type" : "array", "items" : { - "$ref" : "#/components/schemas/ApiAnswerSet" + "$ref" : "#/components/schemas/ApiSubmission" } } },