Skip to content

Commit

Permalink
Fixed some issues relating to the export of the run
Browse files Browse the repository at this point in the history
  • Loading branch information
sauterl committed May 6, 2024
1 parent 823d9b1 commit 4740fb9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,7 +18,7 @@ import kotlinx.dnq.query.query
* @author Ralph Gasser
* @version 1.0.0
*/
class EvaluationDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler<String> {
class EvaluationDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler<ApiEvaluation> {

/** The route of this [EvaluationDownloadHandler]. */
override val route = "download/evaluation/{evaluationId}"
Expand All @@ -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) {
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -18,7 +19,8 @@ import kotlinx.dnq.query.query
* @author Ralph Gasser
* @version 1.0.0
*/
class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(), GetRestHandler<String> {
class EvaluationTemplateDownloadHandler(private val store: TransientEntityStore) : AbstractDownloadHandler(),
GetRestHandler<ApiEvaluationTemplate> {

/** The route of this [EvaluationTemplateDownloadHandler]. */
override val route = "download/template/{templateId}"
Expand All @@ -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) {
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,5 +21,5 @@ data class ApiTask(
val templateId: TemplateId,
val started: Long?,
val ended: Long?,
val submissions: List<ApiAnswerSet>
)
val submissions: List<ApiSubmission>
)
11 changes: 8 additions & 3 deletions backend/src/main/kotlin/dev/dres/data/model/run/DbTask.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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<DbTask,DbAnswerSet>(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].
*
Expand All @@ -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()
)
}
}
6 changes: 3 additions & 3 deletions doc/oas-client.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}" : {
Expand Down Expand Up @@ -1342,7 +1342,7 @@
"submissions" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ApiAnswerSet"
"$ref" : "#/components/schemas/ApiSubmission"
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions doc/oas.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -594,9 +594,9 @@
"200" : {
"description" : "OK",
"content" : {
"text/plain" : {
"application/json" : {
"schema" : {
"type" : "string"
"$ref" : "#/components/schemas/ApiEvaluation"
}
}
}
Expand Down Expand Up @@ -5756,7 +5756,7 @@
"submissions" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ApiAnswerSet"
"$ref" : "#/components/schemas/ApiSubmission"
}
}
},
Expand Down

0 comments on commit 4740fb9

Please sign in to comment.