Skip to content

Commit

Permalink
chore(backend): update dependency (#1598)
Browse files Browse the repository at this point in the history
Updates Exposed from 0.43.0 to 0.49.0
  • Loading branch information
chaoran-chen authored Apr 15, 2024
1 parent bb4e926 commit edddcf0
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 157 deletions.
8 changes: 4 additions & 4 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ dependencies {
implementation "org.apache.commons:commons-csv:1.10.0"
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0"
implementation "org.flywaydb:flyway-core"
implementation "org.jetbrains.exposed:exposed-spring-boot-starter:$exposedVersion"
implementation "org.jetbrains.exposed:exposed-jdbc:$exposedVersion"
implementation "org.jetbrains.exposed:exposed-json:$exposedVersion"
implementation "org.jetbrains.exposed:exposed-kotlin-datetime:$exposedVersion"
implementation "org.jetbrains.exposed:exposed-spring-boot-starter:0.49.0"
implementation "org.jetbrains.exposed:exposed-jdbc:0.49.0"
implementation "org.jetbrains.exposed:exposed-json:0.49.0"
implementation "org.jetbrains.exposed:exposed-kotlin-datetime:0.49.0"
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.5.0"
implementation "org.hibernate.validator:hibernate-validator:8.0.1.Final"
implementation "org.keycloak:keycloak-admin-client:23.0.7"
Expand Down
1 change: 0 additions & 1 deletion backend/gradle.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import org.jetbrains.exposed.sql.batchInsert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.loculus.backend.api.DataUseTerms
import org.loculus.backend.api.DataUseTermsHistoryEntry
import org.loculus.backend.api.DataUseTermsType
Expand Down Expand Up @@ -51,7 +51,8 @@ class DataUseTermsDatabaseService(

fun getDataUseTermsHistory(accession: Accession): List<DataUseTermsHistoryEntry> {
val accessionDataUseTermsHistory = DataUseTermsTable
.select { DataUseTermsTable.accessionColumn eq accession }
.selectAll()
.where { DataUseTermsTable.accessionColumn eq accession }
.sortedBy { it[DataUseTermsTable.changeDateColumn] }
.map {
DataUseTermsHistoryEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlinx.datetime.plus
import kotlinx.datetime.toLocalDateTime
import mu.KotlinLogging
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.loculus.backend.api.DataUseTerms
import org.loculus.backend.api.DataUseTermsType
import org.loculus.backend.controller.BadRequestException
Expand All @@ -22,16 +21,12 @@ class DataUseTermsPreconditionValidator {

fun checkThatTransitionIsAllowed(accessions: List<Accession>, newDataUseTerms: DataUseTerms) {
val dataUseTerms = DataUseTermsTable
.slice(
.select(
DataUseTermsTable.accessionColumn,
DataUseTermsTable.dataUseTermsTypeColumn,
DataUseTermsTable.restrictedUntilColumn,
)
.select(
where = {
(DataUseTermsTable.accessionColumn inList accessions) and DataUseTermsTable.isNewestDataUseTerms
},
)
.where { (DataUseTermsTable.accessionColumn inList accessions) and DataUseTermsTable.isNewestDataUseTerms }

logger.debug {
"Checking that transition is allowed for accessions " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.jetbrains.exposed.sql.alias
import org.jetbrains.exposed.sql.kotlin.datetime.date
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
import org.jetbrains.exposed.sql.max
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.wrapAsExpression

const val DATA_USE_TERMS_TABLE_NAME = "data_use_terms_table"
Expand All @@ -26,10 +25,8 @@ object DataUseTermsTable : Table(DATA_USE_TERMS_TABLE_NAME) {
val subQueryTable = alias("subQueryTable")
return wrapAsExpression(
subQueryTable
.slice(subQueryTable[changeDateColumn].max())
.select {
subQueryTable[accessionColumn] eq accessionColumn
},
.select(subQueryTable[changeDateColumn].max())
.where { subQueryTable[accessionColumn] eq accessionColumn },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.loculus.backend.api.Address
import org.loculus.backend.api.Group
Expand Down Expand Up @@ -101,7 +100,8 @@ class GroupManagementDatabaseService(
(UserGroupsTable.groupIdColumn eq GroupsTable.id)
},
)
.select { UserGroupsTable.userNameColumn eq authenticatedUser.username }
.selectAll()
.where { UserGroupsTable.userNameColumn eq authenticatedUser.username }
}

return groupsQuery.map {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.loculus.backend.service.groupmanagement

import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.loculus.backend.auth.AuthenticatedUser
import org.loculus.backend.controller.ForbiddenException
import org.loculus.backend.controller.NotFoundException
Expand All @@ -26,7 +26,8 @@ class GroupManagementPreconditionValidator(
}

val existingGroups = GroupsTable
.select { GroupsTable.id inList groupIds }
.selectAll()
.where { GroupsTable.id inList groupIds }
.map { it[GroupsTable.id].value }
.toSet()

Expand All @@ -38,7 +39,8 @@ class GroupManagementPreconditionValidator(

val username = authenticatedUser.username
val userGroups = UserGroupsTable
.select {
.selectAll()
.where {
(UserGroupsTable.groupIdColumn inList existingGroups) and
(UserGroupsTable.userNameColumn eq username)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.jetbrains.exposed.sql.andWhere
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.max
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.update
import org.keycloak.representations.idm.UserRepresentation
Expand All @@ -36,7 +35,7 @@ import org.loculus.backend.service.submission.AccessionPreconditionValidator
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.sql.Timestamp
import java.util.UUID
import java.util.*
import javax.sql.DataSource

private val log = KotlinLogging.logger { }
Expand Down Expand Up @@ -111,8 +110,8 @@ class SeqSetCitationsDatabaseService(
val seqSetUUID = UUID.fromString(seqSetId)

val maxVersion = SeqSetsTable
.slice(SeqSetsTable.seqSetVersion.max())
.select { SeqSetsTable.seqSetId eq seqSetUUID and (SeqSetsTable.createdBy eq username) }
.select(SeqSetsTable.seqSetVersion.max())
.where { SeqSetsTable.seqSetId eq seqSetUUID and (SeqSetsTable.createdBy eq username) }
.firstOrNull()
?.get(SeqSetsTable.seqSetVersion.max())

Expand Down Expand Up @@ -142,7 +141,8 @@ class SeqSetCitationsDatabaseService(

for (record in seqSetRecords) {
val existingRecord = SeqSetRecordsTable
.select { SeqSetRecordsTable.accession eq record.accession }
.selectAll()
.where { SeqSetRecordsTable.accession eq record.accession }
.singleOrNull()

val seqSetRecordId = if (existingRecord == null) {
Expand Down Expand Up @@ -174,9 +174,8 @@ class SeqSetCitationsDatabaseService(
log.info { "Get seqSet $seqSetId, version $version" }

val query = SeqSetsTable
.select {
SeqSetsTable.seqSetId eq UUID.fromString(seqSetId)
}
.selectAll()
.where { SeqSetsTable.seqSetId eq UUID.fromString(seqSetId) }

if (version != null) {
query.andWhere { SeqSetsTable.seqSetVersion eq version }
Expand Down Expand Up @@ -208,16 +207,16 @@ class SeqSetCitationsDatabaseService(

if (selectedVersion == null) {
selectedVersion = SeqSetsTable
.slice(SeqSetsTable.seqSetVersion.max())
.select { SeqSetsTable.seqSetId eq seqSetUuid }
.select(SeqSetsTable.seqSetVersion.max())
.where { SeqSetsTable.seqSetId eq seqSetUuid }
.singleOrNull()?.get(SeqSetsTable.seqSetVersion)
}
if (selectedVersion == null) {
throw NotFoundException("SeqSet $seqSetId does not exist")
}

if (SeqSetToRecordsTable
.select {
.selectAll().where {
(SeqSetToRecordsTable.seqSetId eq seqSetUuid) and
(SeqSetToRecordsTable.seqSetVersion eq selectedVersion)
}
Expand All @@ -228,7 +227,8 @@ class SeqSetCitationsDatabaseService(

val selectedSeqSetRecords = SeqSetToRecordsTable
.innerJoin(SeqSetRecordsTable)
.select {
.selectAll()
.where {
(SeqSetToRecordsTable.seqSetId eq seqSetUuid) and
(SeqSetToRecordsTable.seqSetVersion eq selectedVersion)
}
Expand All @@ -248,7 +248,8 @@ class SeqSetCitationsDatabaseService(
log.info { "Get seqSets for user $username" }

val selectedSeqSets = SeqSetsTable
.select { SeqSetsTable.createdBy eq username }
.selectAll()
.where { SeqSetsTable.createdBy eq username }

return selectedSeqSets.map {
SeqSet(
Expand All @@ -270,9 +271,9 @@ class SeqSetCitationsDatabaseService(
val seqSetUuid = UUID.fromString(seqSetId)

val seqSetDOI = SeqSetsTable
.select {
(SeqSetsTable.seqSetId eq seqSetUuid) and
(SeqSetsTable.seqSetVersion eq version) and
.selectAll()
.where {
(SeqSetsTable.seqSetId eq seqSetUuid) and (SeqSetsTable.seqSetVersion eq version) and
(SeqSetsTable.createdBy eq username)
}
.singleOrNull()
Expand All @@ -293,9 +294,9 @@ class SeqSetCitationsDatabaseService(
log.info { "Validate create DOI for seqSet $seqSetId, version $version, user $username" }

if (SeqSetsTable
.select {
(SeqSetsTable.seqSetId eq UUID.fromString(seqSetId)) and
(SeqSetsTable.seqSetVersion eq version) and
.selectAll()
.where {
(SeqSetsTable.seqSetId eq UUID.fromString(seqSetId)) and (SeqSetsTable.seqSetVersion eq version) and
(SeqSetsTable.createdBy eq username)
}
.empty()
Expand All @@ -306,9 +307,9 @@ class SeqSetCitationsDatabaseService(
val now = Clock.System.now().toLocalDateTime(TimeZone.UTC).toJavaLocalDateTime()
val sevenDaysAgo = LocalDateTime.parse(now.minusDays(7).toString())
val count = SeqSetsTable
.select {
(SeqSetsTable.createdBy eq username) and
(SeqSetsTable.createdAt greaterEq sevenDaysAgo) and
.selectAll()
.where {
(SeqSetsTable.createdBy eq username) and (SeqSetsTable.createdAt greaterEq sevenDaysAgo) and
(SeqSetsTable.seqSetDOI neq "")
}
.count()
Expand Down Expand Up @@ -359,8 +360,7 @@ class SeqSetCitationsDatabaseService(

val maxSeqSetVersion = SeqSetsTable.seqSetVersion.max().alias("max_version")
val maxVersionPerSeqSet = SeqSetsTable
.slice(SeqSetsTable.seqSetId, maxSeqSetVersion)
.selectAll()
.select(SeqSetsTable.seqSetId, maxSeqSetVersion)
.groupBy(SeqSetsTable.seqSetId)
.alias("maxVersionPerSeqSet")

Expand All @@ -375,9 +375,8 @@ class SeqSetCitationsDatabaseService(
(SeqSetToRecordsTable.seqSetVersion eq maxVersionPerSeqSet[maxSeqSetVersion])
},
)
.select {
(SeqSetRecordsTable.accession inList userAccessionStrings)
}
.selectAll()
.where { (SeqSetRecordsTable.accession inList userAccessionStrings) }
.map {
SeqSetWithAccession(
it[SeqSetRecordsTable.accession],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.loculus.backend.service.submission

import org.jetbrains.exposed.sql.Query
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.loculus.backend.api.AccessionVersion
import org.loculus.backend.api.AccessionVersionInterface
import org.loculus.backend.api.Organism
Expand Down Expand Up @@ -30,15 +29,15 @@ class AccessionPreconditionValidator(
organism: Organism,
) {
val sequenceEntries = SequenceEntriesView
.slice(
.select(
SequenceEntriesView.accessionColumn,
SequenceEntriesView.versionColumn,
SequenceEntriesView.submitterColumn,
SequenceEntriesView.groupIdColumn,
SequenceEntriesView.statusColumn,
SequenceEntriesView.organismColumn,
)
.select(where = { SequenceEntriesView.accessionVersionIsIn(accessionVersions) })
.where { SequenceEntriesView.accessionVersionIsIn(accessionVersions) }

validateAccessionVersionsExist(sequenceEntries, accessionVersions)
validateSequenceEntriesAreInStates(sequenceEntries, statuses)
Expand All @@ -49,12 +48,12 @@ class AccessionPreconditionValidator(
@Transactional(readOnly = true)
fun validateAccessionVersions(accessionVersions: List<AccessionVersionInterface>, statuses: List<Status>) {
val sequenceEntries = SequenceEntriesView
.slice(
.select(
SequenceEntriesView.accessionColumn,
SequenceEntriesView.versionColumn,
SequenceEntriesView.statusColumn,
)
.select(where = { SequenceEntriesView.accessionVersionIsIn(accessionVersions) })
.where { SequenceEntriesView.accessionVersionIsIn(accessionVersions) }

validateAccessionVersionsExist(sequenceEntries, accessionVersions)
validateSequenceEntriesAreInStates(sequenceEntries, statuses)
Expand All @@ -68,19 +67,15 @@ class AccessionPreconditionValidator(
organism: Organism,
) {
val sequenceEntries = SequenceEntriesView
.slice(
.select(
SequenceEntriesView.accessionColumn,
SequenceEntriesView.versionColumn,
SequenceEntriesView.submitterColumn,
SequenceEntriesView.groupIdColumn,
SequenceEntriesView.statusColumn,
SequenceEntriesView.organismColumn,
)
.select(
where = {
(SequenceEntriesView.accessionColumn inList accessions) and SequenceEntriesView.isMaxVersion
},
)
.where { (SequenceEntriesView.accessionColumn inList accessions) and SequenceEntriesView.isMaxVersion }

validateAccessionsExist(sequenceEntries, accessions)
validateSequenceEntriesAreInStates(sequenceEntries, statuses)
Expand All @@ -91,17 +86,13 @@ class AccessionPreconditionValidator(
@Transactional(readOnly = true)
fun validateAccessions(authenticatedUser: AuthenticatedUser, accessions: List<Accession>) {
val sequenceEntries = SequenceEntriesView
.slice(
.select(
SequenceEntriesView.accessionColumn,
SequenceEntriesView.versionColumn,
SequenceEntriesView.submitterColumn,
SequenceEntriesView.groupIdColumn,
)
.select(
where = {
(SequenceEntriesView.accessionColumn inList accessions) and SequenceEntriesView.isMaxVersion
},
)
.where { (SequenceEntriesView.accessionColumn inList accessions) and SequenceEntriesView.isMaxVersion }

validateAccessionsExist(sequenceEntries, accessions)
validateUserIsAllowedToEditSequenceEntries(sequenceEntries, authenticatedUser)
Expand All @@ -110,17 +101,13 @@ class AccessionPreconditionValidator(
@Transactional(readOnly = true)
fun validateAccessions(accessions: List<Accession>, statuses: List<Status>): List<AccessionVersionGroup> {
val sequenceEntries = SequenceEntriesView
.slice(
.select(
SequenceEntriesView.accessionColumn,
SequenceEntriesView.versionColumn,
SequenceEntriesView.statusColumn,
SequenceEntriesView.groupIdColumn,
)
.select(
where = {
(SequenceEntriesView.accessionColumn inList accessions) and SequenceEntriesView.isMaxVersion
},
)
.where { (SequenceEntriesView.accessionColumn inList accessions) and SequenceEntriesView.isMaxVersion }

validateAccessionsExist(sequenceEntries, accessions)
validateSequenceEntriesAreInStates(sequenceEntries, statuses)
Expand Down
Loading

0 comments on commit edddcf0

Please sign in to comment.