Skip to content

Commit

Permalink
Streamlined the media item references in Api types
Browse files Browse the repository at this point in the history
  • Loading branch information
sauterl committed May 24, 2024
1 parent b7082a4 commit cd85253
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 44 deletions.
2 changes: 1 addition & 1 deletion backend/src/main/kotlin/dev/dres/DRES.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import kotlin.system.exitProcess
*/
object DRES {
/** Version of DRES. */
const val VERSION = "2.0.0"
const val VERSION = "2.0.1-SNAPSHOT"

/** Application root; should be relative to JAR file or classes path. */
val APPLICATION_ROOT: Path =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.dres.api.rest.handler.evaluation.viewer

import dev.dres.DRES
import dev.dres.api.rest.handler.GetRestHandler
import dev.dres.api.rest.handler.evaluation.viewer.AbstractEvaluationViewerHandler
import dev.dres.api.rest.types.ViewerInfo
import dev.dres.api.rest.types.template.tasks.ApiHintContent
import dev.dres.api.rest.types.status.ErrorStatus
Expand Down Expand Up @@ -140,8 +139,8 @@ class GetTaskHintHandler(private val store: TransientEntityStore, private val ca
private fun ApiHint.toContentElement(): ApiContentElement {

//TODO find a better place for this lookup
val item = this.mediaItem?.let {itemId ->
DbMediaItem.filter { it.mediaItemId eq itemId }.firstOrNull()
val item = this.item?.let { item ->
DbMediaItem.filter { it.mediaItemId eq item.mediaItemId }.firstOrNull()
}
val range = if (item?.fps != null) {
this.range?.toTemporalRange(item.fps!!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dres.api.rest.types.template.tasks

import dev.dres.api.rest.types.collection.ApiMediaItem
import dev.dres.api.rest.types.collection.time.ApiTemporalRange
import dev.dres.data.model.template.*
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -65,12 +66,7 @@ data class ApiHint(
*
* This is the reference to the media item
*/
val mediaItem: String? = null,

/**
* This is a reference to the media item's name, in case there is one.
*/
val mediaItemName: String? = null,
val item: ApiMediaItem? = null,

/**
* In case [type] is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.dres.api.rest.types.template.tasks

import dev.dres.api.rest.types.collection.ApiMediaItem
import dev.dres.api.rest.types.collection.time.ApiTemporalRange
import dev.dres.data.model.template.task.DbTaskTemplateTarget
import kotlinx.serialization.Serializable
Expand All @@ -19,7 +20,7 @@ data class ApiTarget(
val target: String? = null,
val range: ApiTemporalRange? = null,
/**
* The name of the target, which is defined for certain types (e.g. [ApiTargetType]-MEDIA_TIEM )
* The target as item, which is only defined for certain types (e.g. [ApiTargetType]-MEDIA_TIEM )
*/
val name: String? = null
val item: ApiMediaItem? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class DbHint(entity: Entity) : XdEntity(entity) {
start = this.start,
end = this.end,
description = this.text,
mediaItem = this.item?.id,
mediaItemName = this.item?.name,
item = this.item?.toApi(),
dataType = this.type.mimeType,
path = this.path,
range = this.range?.let { ApiTemporalRange(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DbTaskTemplateTarget(entity: Entity) : XdEntity(entity) {
type=this.type.toApi(),
target = this.item?.id,
range= this.range?.let { ApiTemporalRange(it) },
name= this.item?.name
item = this.item?.toApi()
)
DbTargetType.TEXT -> ApiTarget(this.type.toApi(), this.text)
else -> throw IllegalStateException("Task description of type ${this.type.description} is not supported.")
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main/kotlin/dev/dres/mgmt/TemplateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ object TemplateManager {
task.hints.add(DbHint.new {
this.type = hint.type.toDb()
this.item =
hint.mediaItem?.let { DbMediaItem.query(DbMediaItem::id eq hint.mediaItem).firstOrNull() }
hint.item?.let { DbMediaItem.query(DbMediaItem::id eq hint.item.mediaItemId).firstOrNull() }
this.text = hint.description

this.path = hint.path
this.start = hint.start
this.end = hint.end
Expand Down
15 changes: 6 additions & 9 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",
"description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0"
"version" : "2.0.1-SNAPSHOT",
"description" : "Client API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.1-SNAPSHOT"
},
"paths" : {
"/api/v2/client/evaluation/currentTask/{evaluationId}" : {
Expand Down Expand Up @@ -2021,11 +2021,8 @@
"dataType" : {
"type" : "string"
},
"mediaItem" : {
"type" : "string"
},
"mediaItemName" : {
"type" : "string"
"item" : {
"$ref" : "#/components/schemas/ApiMediaItem"
},
"range" : {
"$ref" : "#/components/schemas/ApiTemporalRange"
Expand Down Expand Up @@ -2069,8 +2066,8 @@
"range" : {
"$ref" : "#/components/schemas/ApiTemporalRange"
},
"name" : {
"type" : "string"
"item" : {
"$ref" : "#/components/schemas/ApiMediaItem"
}
},
"required" : [ "type" ]
Expand Down
15 changes: 6 additions & 9 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",
"description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.0",
"version" : "2.0.1-SNAPSHOT",
"description" : "API for DRES (Distributed Retrieval Evaluation Server), Version 2.0.1-SNAPSHOT",
"contact" : {
"name" : "The DRES Dev Team",
"url" : "https://dres.dev"
Expand Down Expand Up @@ -6435,11 +6435,8 @@
"dataType" : {
"type" : "string"
},
"mediaItem" : {
"type" : "string"
},
"mediaItemName" : {
"type" : "string"
"item" : {
"$ref" : "#/components/schemas/ApiMediaItem"
},
"range" : {
"$ref" : "#/components/schemas/ApiTemporalRange"
Expand Down Expand Up @@ -6483,8 +6480,8 @@
"range" : {
"$ref" : "#/components/schemas/ApiTemporalRange"
},
"name" : {
"type" : "string"
"item" : {
"$ref" : "#/components/schemas/ApiMediaItem"
}
},
"required" : [ "type" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class CompetitionFormBuilder {
type: c.get('type').value,
start: c.get('start').value,
end: c.get('end').value,
mediaItem: c.get('mediaItem')?.value?.mediaItemId ?? null,
item: c.get('mediaItem')?.value ?? null,
range:
c.get('segment_start') && c.get('segment_end')
? ({
Expand Down Expand Up @@ -236,7 +236,7 @@ export class CompetitionFormBuilder {
type: c.get('type').value,
start: c.get('start').value,
end: c.get('end').value,
mediaItem: c.get('mediaItem')?.value?.mediaItemId ?? null,
item: c.get('mediaItem')?.value ?? null,
range:
c.get('segment_start') && c.get('segment_end')
? ({
Expand Down Expand Up @@ -491,13 +491,13 @@ export class CompetitionFormBuilder {
* @return The new {@link FormGroup}
*/
private imageItemComponentForm(index: number, initialize?: ApiHint): UntypedFormGroup {
if(initialize?.path && !initialize?.mediaItem){
if(initialize?.path && !initialize?.item){
/* Handle external image */
return this.externalImageItemComponentForm(index, initialize);
}
const mediaItemFormControl = new UntypedFormControl(null, [Validators.required, RequireMatch]);
if (
!initialize?.mediaItem &&
!initialize?.item &&
(this.taskType.targetOption === 'SINGLE_MEDIA_SEGMENT' || this.taskType.targetOption === 'SINGLE_MEDIA_ITEM')
) {
mediaItemFormControl.setValue((this.form.get('target') as UntypedFormArray).controls[0].get('mediaItem').value, {emitEvent: false});
Expand All @@ -515,9 +515,9 @@ export class CompetitionFormBuilder {
);

/* Load media item from API. */
if (initialize?.mediaItem && this.data?.collectionId) {
if (initialize?.item && this.data?.collectionId) {
this.collectionService
.getApiV2MediaItemByMediaItemId(initialize?.mediaItem)
.getApiV2MediaItemByMediaItemId(initialize?.item.mediaItemId)
.pipe(first())
.subscribe((s) => {
mediaItemFormControl.setValue(s, {emitEvent: false});
Expand Down Expand Up @@ -546,14 +546,14 @@ export class CompetitionFormBuilder {
* @return The new {@link FormGroup}
*/
private videoItemComponentForm(index: number, initialize?: ApiHint): UntypedFormGroup {
if(initialize?.path && !initialize?.mediaItem){
if(initialize?.path && !initialize?.item){
/* handle external video */
return this.externalVideoItemComponentForm(index, initialize);
}
/* Initialize media item based on target. */
const mediaItemFormControl = new UntypedFormControl(null, [Validators.required, RequireMatch]);
if (
!initialize?.mediaItem &&
!initialize?.item &&
(this.taskType.targetOption === 'SINGLE_MEDIA_SEGMENT' || this.taskType.targetOption === 'SINGLE_MEDIA_ITEM')
) {
mediaItemFormControl.setValue((this.form.get('target') as UntypedFormArray).controls[0].get('mediaItem').value, {emitEvent: false});
Expand All @@ -571,9 +571,9 @@ export class CompetitionFormBuilder {
);

/* Load media item from API. */
if (initialize?.mediaItem && this.data?.collectionId) {
if (initialize?.item && this.data?.collectionId) {
this.collectionService
.getApiV2MediaItemByMediaItemId(initialize.mediaItem)
.getApiV2MediaItemByMediaItemId(initialize.item.mediaItemId)
.pipe(first())
.subscribe((s) => {
mediaItemFormControl.setValue(s, {emitEvent: false});
Expand Down

0 comments on commit cd85253

Please sign in to comment.