diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 398b4ef..5d4e80d 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -18,7 +18,7 @@ @Suppress("ConstPropertyName") object Versions { - const val project = "0.1.8" + const val project = "0.2.2" const val java = 17 diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/ObservationRepositoryImpl.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/ObservationRepositoryImpl.kt index 68f49cb..25083b4 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/ObservationRepositoryImpl.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/ObservationRepositoryImpl.kt @@ -21,6 +21,7 @@ package org.radarbase.datadashboard.api.domain import jakarta.inject.Provider import jakarta.persistence.EntityManager import jakarta.ws.rs.core.Context +import org.hibernate.exception.SQLGrammarException import org.radarbase.datadashboard.api.domain.model.Observation import org.radarbase.jersey.hibernate.HibernateRepository import org.radarbase.jersey.service.AsyncCoroutineService @@ -31,22 +32,40 @@ class ObservationRepositoryImpl( @Context asyncService: AsyncCoroutineService, ) : HibernateRepository(em, asyncService), ObservationRepository { + private val tableExistsRegex = Regex("relation \".*\" does not exist") + override suspend fun getObservations(projectId: String, subjectId: String, topicId: String): List { logger.debug("Get observations in topic {} of subject {} in project {}", topicId, subjectId, projectId) return transact { - createQuery( - "SELECT o FROM Observation o WHERE o.project = :projectId AND o.subject = :subjectId AND o.topic = :topicId ORDER BY o.observationTime DESC", - Observation::class.java, - ).apply { - setParameter("projectId", projectId) - setParameter("subjectId", subjectId) - setParameter("topicId", topicId) - }.resultList + try { + createQuery( + "SELECT o FROM Observation o WHERE o.project = :projectId AND o.subject = :subjectId AND o.topic = :topicId ORDER BY o.observationTime DESC", + Observation::class.java, + ).apply { + setParameter("projectId", projectId) + setParameter("subjectId", subjectId) + setParameter("topicId", topicId) + }.resultList + } catch (ex: SQLGrammarException) { + if (tableDoesNotExist(ex)) { + logger.info( + "Observations table has not been created by JDBC connector yet " + + "(will be created upon first data ingestion). Returning empty result...", + ) + emptyList() + } else { + throw ex + } + } } } companion object { private val logger = LoggerFactory.getLogger(ObservationRepositoryImpl::class.java) } + + private fun tableDoesNotExist(ex: SQLGrammarException): Boolean { + return tableExistsRegex.containsMatchIn(ex.message ?: "") + } }