Skip to content

Commit 96d93e4

Browse files
committed
feat: Allow to mark runs as outdated
This is for cases where for example new resolutions have been added for items found in the run, so that the message can be shown in the UI. Relates to #1009. Signed-off-by: Johanna Lamppu <[email protected]>
1 parent aace8a0 commit 96d93e4

File tree

8 files changed

+93
-5
lines changed

8 files changed

+93
-5
lines changed

api/v1/mapping/src/commonMain/kotlin/ApiMappings.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ fun OrtRun.mapToApi(jobs: ApiJobs) =
391391
resolvedJobConfigContext = resolvedJobConfigContext,
392392
environmentConfigPath = environmentConfigPath,
393393
traceId = traceId,
394-
userDisplayName = userDisplayName?.mapToApi()
394+
userDisplayName = userDisplayName?.mapToApi(),
395+
outdated = outdated,
396+
outdatedMessage = outdatedMessage
395397
)
396398

397399
fun OrtRun.mapToApiSummary(jobs: ApiJobSummaries) =
@@ -412,7 +414,9 @@ fun OrtRun.mapToApiSummary(jobs: ApiJobSummaries) =
412414
jobConfigContext = jobConfigContext,
413415
resolvedJobConfigContext = resolvedJobConfigContext,
414416
environmentConfigPath = environmentConfigPath,
415-
userDisplayName = userDisplayName?.mapToApi()
417+
userDisplayName = userDisplayName?.mapToApi(),
418+
outdated = outdated,
419+
outdatedMessage = outdatedMessage
416420
)
417421

418422
fun OrtRunSummary.mapToApi() =

api/v1/model/src/commonMain/kotlin/OrtRun.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,17 @@ data class OrtRun(
138138
/**
139139
* The display name of the user that triggered the scan.
140140
*/
141-
val userDisplayName: UserDisplayName? = null
141+
val userDisplayName: UserDisplayName? = null,
142+
143+
/**
144+
* A flag to indicate if the results of the run are outdated, e.g. because of a new resolution.
145+
*/
146+
val outdated: Boolean = false,
147+
148+
/**
149+
* A message describing why the results of the run are outdated.
150+
*/
151+
val outdatedMessage: String? = null
142152
)
143153

144154
/**

api/v1/model/src/commonMain/kotlin/OrtRunSummary.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,17 @@ data class OrtRunSummary(
118118
/**
119119
* The display name of the user that triggered this run.
120120
*/
121-
val userDisplayName: UserDisplayName? = null
121+
val userDisplayName: UserDisplayName? = null,
122+
123+
/**
124+
* A flag to indicate if the results of the run are outdated, e.g. because of a new resolution.
125+
*/
126+
val outdated: Boolean = false,
127+
128+
/**
129+
* A message describing why the results of the run are outdated.
130+
*/
131+
val outdatedMessage: String? = null
122132
)
123133

124134
/**

dao/src/main/kotlin/repositories/ortrun/OrtRunsTable.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ object OrtRunsTable : SortableTable("ort_runs") {
8383
val traceId = text("trace_id").nullable()
8484
val environmentConfigPath = text("environment_config_path").nullable()
8585
val userDisplayName = reference("user_id", UserDisplayNamesTable.id).nullable()
86+
val outdated = bool("outdated").default(false)
87+
val outdatedMessage = text("outdated_message").nullable()
8688

8789
/** Get the id of the analyzer run for the given ORT run [id]. Returns `null` if no run is found. */
8890
fun getAnalyzerRunIdById(id: Long): Long? =
@@ -117,6 +119,8 @@ class OrtRunDao(id: EntityID<Long>) : LongEntity(id) {
117119
var vcsProcessedId by OrtRunsTable.vcsProcessedId
118120
var environmentConfigPath by OrtRunsTable.environmentConfigPath
119121
var userDisplayName by UserDisplayNameDao optionalReferencedOn OrtRunsTable.userDisplayName
122+
var outdated by OrtRunsTable.outdated
123+
var outdatedMessage by OrtRunsTable.outdatedMessage
120124

121125
val advisorJob by AdvisorJobDao optionalBackReferencedOn AdvisorJobsTable.ortRunId
122126
val analyzerJob by AnalyzerJobDao optionalBackReferencedOn AnalyzerJobsTable.ortRunId
@@ -152,6 +156,8 @@ class OrtRunDao(id: EntityID<Long>) : LongEntity(id) {
152156
traceId = traceId,
153157
environmentConfigPath = environmentConfigPath,
154158
userDisplayName = userDisplayName?.mapToModel(),
159+
outdated = outdated,
160+
outdatedMessage = outdatedMessage
155161
)
156162

157163
/**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE ort_runs
2+
ADD COLUMN outdated boolean DEFAULT FALSE NOT NULL,
3+
ADD COLUMN outdated_message text NULL;

model/src/commonMain/kotlin/OrtRun.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,17 @@ data class OrtRun(
155155
/**
156156
* Name of the user that triggered this run.
157157
*/
158-
val userDisplayName: UserDisplayName? = null
158+
val userDisplayName: UserDisplayName? = null,
159+
160+
/**
161+
* A flag to indicate if the results of the run are outdated, e.g. because of a new resolution.
162+
*/
163+
val outdated: Boolean = false,
164+
165+
/**
166+
* A message describing why the results of the run are outdated.
167+
*/
168+
val outdatedMessage: String? = null
159169
)
160170

161171
enum class OrtRunStatus(

services/ort-run/src/main/kotlin/OrtRunService.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import kotlinx.datetime.Instant
2525
import org.eclipse.apoapsis.ortserver.dao.blockingQuery
2626
import org.eclipse.apoapsis.ortserver.dao.dbQuery
2727
import org.eclipse.apoapsis.ortserver.dao.repositories.ortrun.OrtRunDao
28+
import org.eclipse.apoapsis.ortserver.dao.repositories.ortrun.OrtRunsTable
2829
import org.eclipse.apoapsis.ortserver.dao.tables.NestedRepositoriesTable
2930
import org.eclipse.apoapsis.ortserver.dao.tables.shared.VcsInfoDao
3031
import org.eclipse.apoapsis.ortserver.model.AdvisorJob
@@ -73,6 +74,7 @@ import org.eclipse.apoapsis.ortserver.services.ResourceNotFoundException
7374

7475
import org.jetbrains.exposed.sql.Database
7576
import org.jetbrains.exposed.sql.insert
77+
import org.jetbrains.exposed.sql.update
7678

7779
import org.ossreviewtoolkit.model.FileList
7880
import org.ossreviewtoolkit.model.OrtResult
@@ -438,6 +440,18 @@ class OrtRunService(
438440
)
439441
}
440442

443+
/**
444+
* Mark the ORT runs with the given [ortRunIds] as outdated with the provided [outdatedMessage].
445+
*/
446+
fun markAsOutdated(ortRunIds: List<Long>, outdatedMessage: String) {
447+
db.blockingQuery {
448+
OrtRunsTable.update({ OrtRunsTable.id inList ortRunIds }) {
449+
it[OrtRunsTable.outdated] = true
450+
it[OrtRunsTable.outdatedMessage] = outdatedMessage
451+
}
452+
}
453+
}
454+
441455
/**
442456
* Start the [AdvisorJob] with the provided [id] and return the updated job or `null` if the job does not exist.
443457
*/

services/ort-run/src/test/kotlin/OrtRunServiceTest.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,37 @@ class OrtRunServiceTest : WordSpec({
13811381
}
13821382
}
13831383
}
1384+
1385+
"markAsOutdated" should {
1386+
"mark the provided runs as outdated and save the describing message" {
1387+
val run1Id = fixtures.createOrtRun().id
1388+
val run2Id = fixtures.createOrtRun().id
1389+
val run3Id = fixtures.createOrtRun().id
1390+
1391+
val outdatedMsg = "Outdated"
1392+
1393+
service.markAsOutdated(listOf(run1Id, run3Id), outdatedMsg)
1394+
1395+
val run1 = service.getOrtRun(run1Id)
1396+
val run2 = service.getOrtRun(run2Id)
1397+
val run3 = service.getOrtRun(run3Id)
1398+
1399+
run1 shouldNotBeNull {
1400+
outdated shouldBe true
1401+
outdatedMessage shouldBe outdatedMessage
1402+
}
1403+
1404+
run2 shouldNotBeNull {
1405+
outdated shouldBe false
1406+
outdatedMessage shouldBe null
1407+
}
1408+
1409+
run3 shouldNotBeNull {
1410+
outdated shouldBe true
1411+
outdatedMessage shouldBe outdatedMessage
1412+
}
1413+
}
1414+
}
13841415
})
13851416

13861417
private fun createOrtRun(

0 commit comments

Comments
 (0)