-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use radar-jersey 0.11.1 and fix tests
- Loading branch information
1 parent
4aa1d7d
commit 905ea2d
Showing
11 changed files
with
196 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...backend/src/main/java/org/radarbase/datadashboard/api/domain/ObservationRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* * Copyright 2024 The Hyve | ||
* * | ||
* * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * you may not use this file except in compliance with the License. | ||
* * You may obtain a copy of the License at | ||
* * | ||
* * http://www.apache.org/licenses/LICENSE-2.0 | ||
* * | ||
* * Unless required by applicable law or agreed to in writing, software | ||
* * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * See the License for the specific language governing permissions and | ||
* * limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.radarbase.datadashboard.api.domain | ||
|
||
import jakarta.inject.Provider | ||
import jakarta.persistence.EntityManager | ||
import jakarta.ws.rs.core.Context | ||
import org.radarbase.datadashboard.api.domain.model.Observation | ||
import org.radarbase.jersey.hibernate.HibernateRepository | ||
import org.radarbase.jersey.service.AsyncCoroutineService | ||
import org.slf4j.LoggerFactory | ||
|
||
class ObservationRepositoryImpl( | ||
@Context em: Provider<EntityManager>, | ||
@Context asyncService: AsyncCoroutineService, | ||
) : HibernateRepository(em, asyncService), ObservationRepository { | ||
|
||
override suspend fun getObservations(projectId: String, subjectId: String, topicId: String): List<Observation> { | ||
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 | ||
} | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(ObservationRepositoryImpl::class.java) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...d-backend/src/main/java/org/radarbase/datadashboard/api/service/ObservationServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* | ||
* * Copyright 2024 The Hyve | ||
* * | ||
* * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * you may not use this file except in compliance with the License. | ||
* * You may obtain a copy of the License at | ||
* * | ||
* * http://www.apache.org/licenses/LICENSE-2.0 | ||
* * | ||
* * Unless required by applicable law or agreed to in writing, software | ||
* * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * See the License for the specific language governing permissions and | ||
* * limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.radarbase.datadashboard.api.service | ||
|
||
import jakarta.ws.rs.core.Context | ||
import org.radarbase.datadashboard.api.api.ObservationListDto | ||
import org.radarbase.datadashboard.api.domain.ObservationRepository | ||
import org.radarbase.datadashboard.api.domain.mapper.toDto | ||
|
||
class ObservationServiceImpl( | ||
@Context private val observationRepository: ObservationRepository, | ||
) : ObservationService { | ||
override suspend fun getObservations(projectId: String, subjectId: String, topicId: String): ObservationListDto { | ||
val result = this.observationRepository.getObservations(projectId = projectId, topicId = topicId, subjectId = subjectId) | ||
return ObservationListDto( | ||
result.map { it.toDto() }, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...d-backend/src/test/java/org/radarbase/datadashboard/api/mock/MockAsyncCoroutineService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.radarbase.upload.mock | ||
|
||
import jakarta.ws.rs.container.AsyncResponse | ||
import kotlinx.coroutines.CancellableContinuation | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
import org.radarbase.jersey.service.AsyncCoroutineService | ||
import kotlin.time.Duration | ||
|
||
class MockAsyncCoroutineService : AsyncCoroutineService { | ||
override fun <T> runAsCoroutine( | ||
asyncResponse: AsyncResponse, | ||
timeout: Duration, | ||
block: suspend () -> T, | ||
) { | ||
runBlocking { | ||
val result = block() | ||
asyncResponse.resume(result) | ||
} | ||
} | ||
|
||
override fun <T> runBlocking(timeout: Duration, block: suspend () -> T): T = | ||
kotlinx.coroutines.runBlocking { | ||
block() | ||
} | ||
|
||
override suspend fun <T> runInRequestScope(block: () -> T): T = block() | ||
|
||
override suspend fun <T> suspendInRequestScope(block: (CancellableContinuation<T>) -> Unit): T = suspendCancellableCoroutine(block) | ||
override suspend fun <T> withContext(name: String, block: suspend () -> T): T { | ||
TODO("Not yet implemented") | ||
} | ||
} |
Oops, something went wrong.