Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:dres-dev/DRES into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sauterl committed Sep 28, 2023
2 parents e98dbb3 + 4661b50 commit 02b3878
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 732 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ class ClientOpenApiPlugin : OpenApiPlugin(OpenApiPluginConfiguration()
"/evaluation/template",
"/evaluation/{evaluationId}/judge",
"/evaluation/{evaluationId}/vote",
"/evaluation/{evaluationId}/submission",
"/evaluation/{evaluationId}/task",
"/evaluation/{evaluationId}/{taskId}",
"/download",
"/mediaitem",
"/template"
"/template",
"/preview",
"/status/info"
)

val relevantRoutes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import dev.dres.api.rest.types.status.ErrorStatus
import dev.dres.api.rest.types.status.ErrorStatusException
import dev.dres.api.rest.types.status.SuccessStatus
import dev.dres.data.model.run.DbEvaluation
import dev.dres.data.model.run.RunProperties
import dev.dres.data.model.run.ApiRunProperties
import dev.dres.utilities.extensions.evaluationId
import io.javalin.http.BadRequestResponse
import io.javalin.http.Context
import io.javalin.http.bodyAsClass
import io.javalin.openapi.*
import jetbrains.exodus.database.TransientEntityStore

/**
* A [PatchRestHandler] handler to adjust an ongoing [DbEvaluation]'s [RunProperties].
* A [PatchRestHandler] handler to adjust an ongoing [DbEvaluation]'s [ApiRunProperties].
*
* @author Ralph Gasser
* @author Luca Rossetto
Expand All @@ -32,7 +31,7 @@ class AdjustPropertiesHandler : AbstractEvaluationAdminHandler(), PatchRestHandl
pathParams = [
OpenApiParam("evaluationId", String::class, "The evaluation ID", required = true, allowEmptyValue = false),
],
requestBody = OpenApiRequestBody([OpenApiContent(RunProperties::class)]),
requestBody = OpenApiRequestBody([OpenApiContent(ApiRunProperties::class)]),
tags = ["Evaluation Administrator"],
responses = [
OpenApiResponse("200", [OpenApiContent(SuccessStatus::class)]),
Expand All @@ -43,7 +42,7 @@ class AdjustPropertiesHandler : AbstractEvaluationAdminHandler(), PatchRestHandl
)
override fun doPatch(ctx: Context): SuccessStatus {
val properties = try {
ctx.bodyAsClass<RunProperties>()
ctx.bodyAsClass<ApiRunProperties>()
} catch (e: BadRequestResponse) {
throw ErrorStatusException(400, "Invalid parameters. This is a programmers error!", ctx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,14 @@ class ClientListEvaluationsHandler : AbstractEvaluationClientHandler(), GetRestH
OpenApiResponse("200", [OpenApiContent(Array<ApiEvaluationInfo>::class)]),
OpenApiResponse("401", [OpenApiContent(ErrorStatus::class)])
],
queryParams = [
OpenApiParam("session", String::class, "Session Token")
],
methods = [HttpMethod.GET]
)
override fun doGet(ctx: Context): List<ApiEvaluationInfo> {
return getRelevantManagers(ctx).map {
ApiEvaluationInfo(
id = it.evaluation.id,
name = it.name,
when (it) {
is InteractiveAsynchronousRunManager -> ApiEvaluationType.ASYNCHRONOUS
is InteractiveSynchronousRunManager -> ApiEvaluationType.SYNCHRONOUS
else -> TODO()
},
properties = it.runProperties,
templateId = it.template.id,
templateDescription = it.template.description,
teams = emptyList(),
taskTemplates = emptyList()
)
ApiEvaluationInfo(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ClientTaskInfoHandler : AbstractEvaluationClientHandler(),
pathParams = [
OpenApiParam("evaluationId", String::class, "The evaluation ID.", required = true, allowEmptyValue = false)
],
queryParams = [
OpenApiParam("session", String::class, "Session Token")
],
responses = [
OpenApiResponse("200", [OpenApiContent(ApiTaskTemplateInfo::class)]),
OpenApiResponse("401", [OpenApiContent(ErrorStatus::class)]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ class SubmissionHandler(private val store: TransientEntityStore): PostRestHandle
path = "/api/v2/submit/{evaluationId}",
methods = [HttpMethod.POST],
operationId = OpenApiOperation.AUTO_GENERATE,
requestBody = OpenApiRequestBody([OpenApiContent(ApiClientSubmission::class)]),
requestBody = OpenApiRequestBody([OpenApiContent(ApiClientSubmission::class)], required = true),
pathParams = [
OpenApiParam("evaluationId", String::class, "The ID of the evaluation the submission belongs to.", required = true),
],
queryParams = [
OpenApiParam("session", String::class, "Session Token")
],
responses = [
OpenApiResponse("200", [OpenApiContent(SuccessfulSubmissionsStatus::class)], description = "The submission was accepted by the server and there was a verdict"),
OpenApiResponse("202", [OpenApiContent(SuccessfulSubmissionsStatus::class)],description = "The submission was accepted by the server and there has not yet been a verdict available"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.dres.api.rest.types.evaluation

import dev.dres.data.model.run.RunProperties
import dev.dres.data.model.run.ApiRunProperties
import dev.dres.run.InteractiveAsynchronousRunManager
import dev.dres.run.InteractiveSynchronousRunManager
import dev.dres.run.NonInteractiveRunManager
Expand All @@ -18,7 +18,8 @@ data class ApiEvaluationInfo(
val id: String,
val name: String,
val type: ApiEvaluationType,
val properties: RunProperties, // FIXME non-api type exposed via
val status: ApiEvaluationStatus,
val properties: ApiRunProperties,
val templateId: String,
val templateDescription: String?,
val teams: List<ApiTeamInfo>,
Expand All @@ -33,6 +34,7 @@ data class ApiEvaluationInfo(
is NonInteractiveRunManager -> ApiEvaluationType.NON_INTERACTIVE
else -> throw IllegalStateException("Incompatible type of run manager.")
},
manager.status.toApi(),
manager.runProperties,
manager.template.id,
manager.template.description,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.dres.api.rest.types.evaluation.submission

import com.fasterxml.jackson.annotation.JsonIgnore
import dev.dres.data.model.media.DbMediaItem
import dev.dres.data.model.media.MediaItemId
import dev.dres.data.model.submissions.DbAnswer
import dev.dres.data.model.submissions.DbAnswerType
import io.javalin.openapi.OpenApiIgnore
import kotlinx.dnq.query.filter
import kotlinx.dnq.query.singleOrNull

Expand All @@ -20,6 +22,8 @@ data class ApiClientAnswer(
val text: String? = null,

/** The [MediaItemId] associated with the [ApiClientAnswer]. Is usually added as contextual information by the receiving endpoint. */
@JsonIgnore
@get:OpenApiIgnore
val mediaItemId: MediaItemId? = null,

/** The name of the media item that is part of the answer. */
Expand Down Expand Up @@ -65,7 +69,7 @@ data class ApiClientAnswer(
*
* @return The [DbAnswerType] for this [ApiClientAnswer].
*/
fun tryDetermineType() = when {
private fun tryDetermineType() = when {
this.mediaItemName != null && this.start != null && this.end != null -> DbAnswerType.TEMPORAL
this.mediaItemName != null -> DbAnswerType.ITEM
this.text != null -> DbAnswerType.TEXT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.dres.api.rest.types.template

import dev.dres.api.rest.types.evaluation.ApiEvaluationType
import dev.dres.data.model.run.RunProperties
import dev.dres.data.model.run.ApiRunProperties
import dev.dres.data.model.template.TemplateId

/**
Expand All @@ -10,4 +10,4 @@ import dev.dres.data.model.template.TemplateId
* @author Ralph Gasser
* @version 1.1.0
*/
data class ApiEvaluationStartMessage(val templateId: TemplateId, val name: String, val type: ApiEvaluationType, val properties: RunProperties = RunProperties())
data class ApiEvaluationStartMessage(val templateId: TemplateId, val name: String, val type: ApiEvaluationType, val properties: ApiRunProperties = ApiRunProperties())
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.annotation.Nulls
import io.javalin.openapi.OpenApiIgnore

enum class QueryEventCategory {
TEXT, IMAGE, SKETCH, FILTER, BROWSING, COOPERATION, OTHER
Expand All @@ -24,6 +25,7 @@ data class QueryEventLog internal constructor(
val events: List<QueryEvent> = emptyList(),
@field:JsonIgnore
@get:JsonIgnore
@get:OpenApiIgnore
internal val serverTimeStamp: Long = System.currentTimeMillis()
)

Expand All @@ -47,5 +49,6 @@ data class QueryResultLog internal constructor(
val events: List<QueryEvent> = emptyList(),
@field:JsonIgnore
@get:JsonIgnore
@get:OpenApiIgnore
internal val serverTimeStamp: Long = System.currentTimeMillis()
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.dres.data.model.run
/**
*
*/
data class RunProperties ( // TODO shoudln't we move this to db and api ?
data class ApiRunProperties (
val participantCanView: Boolean = true,
val shuffleTasks: Boolean = false, //is only used for asynchronous runs
val allowRepeatedTasks: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class InteractiveAsynchronousRunManager(
private val LOGGER = LoggerFactory.getLogger(InteractiveAsynchronousRunManager::class.java)
}

/** Generates and returns [RunProperties] for this [InteractiveAsynchronousRunManager]. */
override val runProperties: RunProperties
get() = RunProperties(
/** Generates and returns [ApiRunProperties] for this [InteractiveAsynchronousRunManager]. */
override val runProperties: ApiRunProperties
get() = ApiRunProperties(
this.evaluation.participantCanView,
false,
this.evaluation.allowRepeatedTasks,
Expand Down Expand Up @@ -200,7 +200,7 @@ class InteractiveAsynchronousRunManager(
/**
*
*/
override fun updateProperties(properties: RunProperties) {
override fun updateProperties(properties: ApiRunProperties) {
TODO("Not yet implemented")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class InteractiveSynchronousRunManager(override val evaluation: InteractiveSynch
private val LOGGER = LoggerFactory.getLogger(InteractiveSynchronousRunManager::class.java)
}

/** Generates and returns [RunProperties] for this [InteractiveAsynchronousRunManager]. */
override val runProperties: RunProperties
get() = RunProperties(this.evaluation.participantCanView, false, this.evaluation.allowRepeatedTasks, this.evaluation.limitSubmissionPreviews)
/** Generates and returns [ApiRunProperties] for this [InteractiveAsynchronousRunManager]. */
override val runProperties: ApiRunProperties
get() = ApiRunProperties(this.evaluation.participantCanView, false, this.evaluation.allowRepeatedTasks, this.evaluation.limitSubmissionPreviews)

/** [EvaluationId] of this [InteractiveSynchronousRunManager]. */
override val id: EvaluationId
Expand Down Expand Up @@ -154,11 +154,11 @@ class InteractiveSynchronousRunManager(override val evaluation: InteractiveSynch
}

/**
* Updates the [RunProperties] for the [InteractiveSynchronousEvaluation] backing this [InteractiveSynchronousRunManager].
* Updates the [ApiRunProperties] for the [InteractiveSynchronousEvaluation] backing this [InteractiveSynchronousRunManager].
*
* @param properties The set of new [RunProperties]
* @param properties The set of new [ApiRunProperties]
*/
override fun updateProperties(properties: RunProperties) {
override fun updateProperties(properties: ApiRunProperties) {
store.transactional {
this.evaluation.allowRepeatedTasks = properties.allowRepeatedTasks
this.evaluation.limitSubmissionPreviews = properties.limitSubmissionPreviews
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class NonInteractiveRunManager(

private val LOGGER = LoggerFactory.getLogger(this.javaClass)

/** Generates and returns [RunProperties] for this [InteractiveAsynchronousRunManager]. */
override val runProperties: RunProperties
get() = RunProperties(
/** Generates and returns [ApiRunProperties] for this [InteractiveAsynchronousRunManager]. */
override val runProperties: ApiRunProperties
get() = ApiRunProperties(
this.evaluation.participantCanView,
false,
this.evaluation.allowRepeatedTasks,
Expand Down Expand Up @@ -85,7 +85,7 @@ class NonInteractiveRunManager(
LOGGER.info("SynchronousRunManager ${this.id} terminated")
}

override fun updateProperties(properties: RunProperties) {
override fun updateProperties(properties: ApiRunProperties) {
TODO("Not yet implemented")
}

Expand Down
9 changes: 4 additions & 5 deletions backend/src/main/kotlin/dev/dres/run/RunManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.dres.run
import dev.dres.api.rest.types.ViewerInfo
import dev.dres.api.rest.types.evaluation.submission.ApiClientSubmission
import dev.dres.api.rest.types.evaluation.submission.ApiSubmission
import dev.dres.api.rest.types.evaluation.websocket.ClientMessage
import dev.dres.api.rest.types.template.ApiEvaluationTemplate
import dev.dres.data.model.run.*
import dev.dres.data.model.run.interfaces.EvaluationId
Expand Down Expand Up @@ -54,7 +53,7 @@ interface RunManager : Runnable {
val judgementValidators: List<JudgementValidator>

/** [JudgementValidator]s for all tasks that use them */
val runProperties: RunProperties
val runProperties: ApiRunProperties

/** The [TransientEntityStore] that backs this [InteractiveRunManager]. */
val store: TransientEntityStore
Expand Down Expand Up @@ -84,11 +83,11 @@ interface RunManager : Runnable {
fun end(context: RunActionContext)

/**
* Updates the [RunProperties] for this [RunManager].
* Updates the [ApiRunProperties] for this [RunManager].
*
* @param properties The new [RunProperties]
* @param properties The new [ApiRunProperties]
*/
fun updateProperties(properties: RunProperties)
fun updateProperties(properties: ApiRunProperties)

/**
* Returns the number of [DbTask]s held by this [RunManager].
Expand Down
Loading

0 comments on commit 02b3878

Please sign in to comment.