Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pvannierop committed May 14, 2024
1 parent 680a063 commit 26f5100
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package org.radarbase.datadashboard.api.api

/** Single observation or data point. */
data class ObservationDto(
/** Unique observation ID. */
val id: Long?,

/** Unique identifier of project. */
val project: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ data class DashboardServiceConfig(
tokenExpiryTimeInMinutes = System.getenv("RADAR_DATA_DASHBOARD_TOKEN_EXPIRY_TIME_IN_MINUTES")?.toLong() ?: tokenExpiryTimeInMinutes,
persistentTokenExpiryInMin = System.getenv("RADAR_DATA_DASHBOARD_PERSISTENT_TOKEN_EXPIRY_IN_MIN")?.toLong() ?: persistentTokenExpiryInMin,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ fun Observation.toDto(): ObservationDto = ObservationDto(
source = source,
topic = topic,
category = category,
date = date?.toString(),
period = if (date != null && endDate != null) {
date = date.toString(),
period = if (endDate != null) {
Duration.between(date, endDate).toString()
} else {
null
},
value = valueNumeric ?: valueTextual,
)

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

package org.radarbase.datadashboard.api.domain.model

import jakarta.persistence.*
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.time.ZonedDateTime
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DashBoardApiEnhancerFactory(
HibernateResourceEnhancer(
config.database.copy(
managedClasses = listOf(
Observation::class.jvmName
Observation::class.jvmName,
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

package org.radarbase.datadashboard.api.enhancer

import jakarta.inject.Singleton
import org.glassfish.jersey.internal.inject.AbstractBinder
import org.radarbase.datadashboard.api.config.DashboardApiConfig
import org.radarbase.datadashboard.api.domain.ObservationRepository
import org.radarbase.datadashboard.api.service.ObservationService
import jakarta.inject.Singleton
import org.glassfish.jersey.internal.inject.AbstractBinder
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer
import org.radarbase.jersey.filter.Filters

Expand Down Expand Up @@ -51,6 +51,5 @@ class DashboardApiEnhancer(
bind(ObservationRepository::class.java)
.to(ObservationRepository::class.java)
.`in`(Singleton::class.java)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
package org.radarbase.datadashboard.api.resource

import jakarta.annotation.Resource
import jakarta.ws.rs.*
import jakarta.ws.rs.Consumes
import jakarta.ws.rs.GET
import jakarta.ws.rs.NotFoundException
import jakarta.ws.rs.Path
import jakarta.ws.rs.PathParam
import jakarta.ws.rs.Produces
import jakarta.ws.rs.container.ContainerRequestContext
import jakarta.ws.rs.core.Context
import org.radarbase.datadashboard.api.service.ObservationService
import org.radarbase.auth.authorization.Permission
import org.radarbase.datadashboard.api.api.ObservationListDto
import org.radarbase.datadashboard.api.service.ObservationService
import org.radarbase.jersey.auth.Authenticated
import org.radarbase.jersey.auth.NeedsPermission
import org.radarbase.jersey.auth.filter.RadarSecurityContext
Expand All @@ -37,15 +42,15 @@ import org.slf4j.LoggerFactory
@Authenticated
class ObservationResource(
@Context private val observationService: ObservationService,
@Context private val request: ContainerRequestContext
@Context private val request: ContainerRequestContext,
) {
@GET
@Path("observations")
@NeedsPermission(Permission.MEASUREMENT_READ)
fun getObservations(
@PathParam("projectId") projectId: String,
@PathParam("subjectId") subjectId: String,
@PathParam("topicId") topicId: String
@PathParam("topicId") topicId: String,
): ObservationListDto {
if (request.securityContext != null && request.securityContext is RadarSecurityContext) {
val userName = (request.securityContext as RadarSecurityContext).userPrincipal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.radarbase.datadashboard.api.domain.ObservationRepository
import org.radarbase.datadashboard.api.domain.mapper.toDto

class ObservationService(
@Context private val observationRepository: ObservationRepository
@Context private val observationRepository: ObservationRepository,
) {
fun getObservations(projectId: String, subjectId: String, topicId: String): ObservationListDto {
val result = this.observationRepository.getObservations(projectId = projectId, topicId = topicId, subjectId = subjectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import org.radarbase.jersey.auth.AuthValidator
import org.radarbase.jersey.auth.disabled.DisabledAuthValidator
import org.radarbase.jersey.config.ConfigLoader


class DashboardIntegrationTest: JerseyTest() {
class DashboardIntegrationTest : JerseyTest() {

lateinit var disabledAuthValidator: DisabledAuthValidator

Expand Down Expand Up @@ -85,5 +84,4 @@ class DashboardIntegrationTest: JerseyTest() {
}

// TODO add more tests that include the token validation.

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.radarbase.datadashboard.api.domain.model.Observation
import org.radarbase.datadashboard.api.service.ObservationService
import java.time.ZonedDateTime

class ObservationResourceTest: JerseyTest() {
class ObservationResourceTest : JerseyTest() {

@Mock
lateinit var observationService: ObservationService
Expand Down Expand Up @@ -109,8 +109,7 @@ class ObservationResourceTest: JerseyTest() {
date = ZonedDateTime.now(),
valueTextual = "value1",
valueNumeric = null,
endDate = null
endDate = null,
)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class ObservationServiceTest {
* */
@Test
fun test_getObservations1() {

// Create some fake observations that are returned by the repository.
// Each observation is linked to a Variable.
val observations: List<Observation> = listOf(createObservation(), createObservation(), createObservation(), createObservation())
Expand All @@ -66,7 +65,7 @@ class ObservationServiceTest {

// Check if the result is as expected (observations transformed to ObservationListDto).
val expectedDto = ObservationListDto(
observations.map { it.toDto() }
observations.map { it.toDto() },
)
assertEquals(expectedDto, result)
}
Expand All @@ -82,8 +81,7 @@ class ObservationServiceTest {
date = ZonedDateTime.now(),
valueTextual = "value1",
valueNumeric = null,
endDate = null
endDate = null,
)
}

}
}

0 comments on commit 26f5100

Please sign in to comment.