Skip to content

Commit

Permalink
Changed return type of ClientListEvaluationsHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaro committed Dec 19, 2023
1 parent 29b5a5b commit c8e0422
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package dev.dres.api.rest.handler.evaluation.client

import dev.dres.api.rest.handler.GetRestHandler
import dev.dres.api.rest.types.evaluation.ApiEvaluationType
import dev.dres.api.rest.types.evaluation.ApiEvaluationInfo
import dev.dres.api.rest.types.evaluation.ApiClientEvaluationInfo
import dev.dres.api.rest.types.status.ErrorStatus
import dev.dres.data.model.run.DbEvaluation
import dev.dres.run.InteractiveAsynchronousRunManager
import dev.dres.run.InteractiveSynchronousRunManager
import io.javalin.http.Context
import io.javalin.openapi.*

Expand All @@ -18,7 +15,7 @@ import io.javalin.openapi.*
* @author Loris Sauter
* @version 2.0.0
*/
class ClientListEvaluationsHandler : AbstractEvaluationClientHandler(), GetRestHandler<List<ApiEvaluationInfo>> {
class ClientListEvaluationsHandler : AbstractEvaluationClientHandler(), GetRestHandler<List<ApiClientEvaluationInfo>> {

override val route = "client/evaluation/list"

Expand All @@ -28,17 +25,17 @@ class ClientListEvaluationsHandler : AbstractEvaluationClientHandler(), GetRestH
operationId = OpenApiOperation.AUTO_GENERATE,
tags = ["Evaluation Client"],
responses = [
OpenApiResponse("200", [OpenApiContent(Array<ApiEvaluationInfo>::class)]),
OpenApiResponse("200", [OpenApiContent(Array<ApiClientEvaluationInfo>::class)]),
OpenApiResponse("401", [OpenApiContent(ErrorStatus::class)])
],
queryParams = [
OpenApiParam("session", String::class, "Session Token")
],
methods = [HttpMethod.GET]
)
override fun doGet(ctx: Context): List<ApiEvaluationInfo> {
override fun doGet(ctx: Context): List<ApiClientEvaluationInfo> {
return getRelevantManagers(ctx).map {
ApiEvaluationInfo(it)
ApiClientEvaluationInfo(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dev.dres.api.rest.types.evaluation

import dev.dres.data.model.run.ApiRunProperties
import dev.dres.run.InteractiveAsynchronousRunManager
import dev.dres.run.InteractiveSynchronousRunManager
import dev.dres.run.NonInteractiveRunManager
import dev.dres.run.RunManager

/**
* Contains the basic and most importantly static information about a [RunManager] that is relevant to a participant.
*
*/
data class ApiClientEvaluationInfo(
val id: String,
val name: String,
val type: ApiEvaluationType,
val status: ApiEvaluationStatus,
val templateId: String,
val templateDescription: String?,
val teams: List<String>,
val taskTemplates: List<ApiClientTaskTemplateInfo>,
) {
constructor(manager: RunManager): this(
manager.id,
manager.name,
when(manager) {
is InteractiveSynchronousRunManager -> ApiEvaluationType.SYNCHRONOUS
is InteractiveAsynchronousRunManager -> ApiEvaluationType.ASYNCHRONOUS
is NonInteractiveRunManager -> ApiEvaluationType.NON_INTERACTIVE
else -> throw IllegalStateException("Incompatible type of run manager.")
},
manager.status.toApi(),
manager.template.id,
manager.template.description,
manager.template.teams.asSequence().map { team -> team.name ?: "" }.toList(),
manager.template.tasks.map { task -> ApiClientTaskTemplateInfo(task) }.toList()
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.dres.api.rest.types.evaluation

import dev.dres.api.rest.types.template.tasks.ApiTaskTemplate
import dev.dres.data.model.template.task.DbTaskTemplate

/**
* Basic and most importantly static information about a [DbTaskTemplate] relevant to the participant.
*/
data class ApiClientTaskTemplateInfo(
val name: String,
val taskGroup: String,
val taskType: String,
val duration: Long
) {
constructor(task: ApiTaskTemplate) : this(
task.name,
task.taskGroup,
task.taskType,
task.duration
)
}
63 changes: 60 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",
"description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0",
"version" : "2.0.0"
"description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0-RC2",
"version" : "2.0.0-RC2"
},
"paths" : {
"/api/v1/submit" : {
Expand Down Expand Up @@ -237,7 +237,7 @@
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ApiEvaluationInfo"
"$ref" : "#/components/schemas/ApiClientEvaluationInfo"
}
}
}
Expand Down Expand Up @@ -1228,6 +1228,63 @@
"type" : "string",
"enum" : [ "FRAME_NUMBER", "SECONDS", "MILLISECONDS", "TIMECODE" ]
},
"ApiClientEvaluationInfo" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"id" : {
"type" : "string"
},
"name" : {
"type" : "string"
},
"type" : {
"$ref" : "#/components/schemas/ApiEvaluationType"
},
"status" : {
"$ref" : "#/components/schemas/ApiEvaluationStatus"
},
"templateId" : {
"type" : "string"
},
"templateDescription" : {
"type" : "string"
},
"teams" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"taskTemplates" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ApiClientTaskTemplateInfo"
}
}
},
"required" : [ "id", "name", "type", "status", "templateId", "teams", "taskTemplates" ]
},
"ApiClientTaskTemplateInfo" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"name" : {
"type" : "string"
},
"taskGroup" : {
"type" : "string"
},
"taskType" : {
"type" : "string"
},
"duration" : {
"type" : "integer",
"format" : "int64"
}
},
"required" : [ "name", "taskGroup", "taskType", "duration" ]
},
"ApiEvaluation" : {
"type" : "object",
"additionalProperties" : false,
Expand Down
63 changes: 60 additions & 3 deletions doc/oas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"openapi" : "3.0.3",
"info" : {
"title" : "DRES API",
"description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0",
"description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0-RC2",
"contact" : {
"name" : "The DRES Dev Team",
"url" : "https://dres.dev"
},
"license" : {
"name" : "MIT"
},
"version" : "2.0.0"
"version" : "2.0.0-RC2"
},
"paths" : {
"/api/v1/submit" : {
Expand Down Expand Up @@ -244,7 +244,7 @@
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ApiEvaluationInfo"
"$ref" : "#/components/schemas/ApiClientEvaluationInfo"
}
}
}
Expand Down Expand Up @@ -5642,6 +5642,63 @@
"type" : "string",
"enum" : [ "FRAME_NUMBER", "SECONDS", "MILLISECONDS", "TIMECODE" ]
},
"ApiClientEvaluationInfo" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"id" : {
"type" : "string"
},
"name" : {
"type" : "string"
},
"type" : {
"$ref" : "#/components/schemas/ApiEvaluationType"
},
"status" : {
"$ref" : "#/components/schemas/ApiEvaluationStatus"
},
"templateId" : {
"type" : "string"
},
"templateDescription" : {
"type" : "string"
},
"teams" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"taskTemplates" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ApiClientTaskTemplateInfo"
}
}
},
"required" : [ "id", "name", "type", "status", "templateId", "teams", "taskTemplates" ]
},
"ApiClientTaskTemplateInfo" : {
"type" : "object",
"additionalProperties" : false,
"properties" : {
"name" : {
"type" : "string"
},
"taskGroup" : {
"type" : "string"
},
"taskType" : {
"type" : "string"
},
"duration" : {
"type" : "integer",
"format" : "int64"
}
},
"required" : [ "name", "taskGroup", "taskType", "duration" ]
},
"ApiEvaluation" : {
"type" : "object",
"additionalProperties" : false,
Expand Down

0 comments on commit c8e0422

Please sign in to comment.