From 26f5100854a1b547a690f99ae03da960b733834d Mon Sep 17 00:00:00 2001 From: Pim van Nierop Date: Tue, 14 May 2024 14:30:27 +0200 Subject: [PATCH] Fix linting errors --- .../datadashboard/api/api/ObservationDto.kt | 2 -- .../api/config/DashboardServiceConfig.kt | 2 +- .../datadashboard/api/domain/mapper/Extensions.kt | 5 ++--- .../datadashboard/api/domain/model/Observation.kt | 5 ++++- .../api/enhancer/DashBoardApiEnhancerFactory.kt | 2 +- .../api/enhancer/DashboardApiEnhancer.kt | 5 ++--- .../api/resource/ObservationResource.kt | 13 +++++++++---- .../datadashboard/api/service/ObservationService.kt | 2 +- .../datadashboard/api/DashboardIntegrationTest.kt | 4 +--- .../api/resource/ObservationResourceTest.kt | 7 +++---- .../api/service/ObservationServiceTest.kt | 8 +++----- 11 files changed, 27 insertions(+), 28 deletions(-) diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/api/ObservationDto.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/api/ObservationDto.kt index eaf7d0b..a461531 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/api/ObservationDto.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/api/ObservationDto.kt @@ -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?, diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardServiceConfig.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardServiceConfig.kt index 4e08ba0..74149bb 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardServiceConfig.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/config/DashboardServiceConfig.kt @@ -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, ) -} \ No newline at end of file +} diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/mapper/Extensions.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/mapper/Extensions.kt index 4a1a299..c6b46d8 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/mapper/Extensions.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/mapper/Extensions.kt @@ -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, ) - diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/model/Observation.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/model/Observation.kt index cae8c91..2b4378e 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/model/Observation.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/domain/model/Observation.kt @@ -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.* diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/enhancer/DashBoardApiEnhancerFactory.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/enhancer/DashBoardApiEnhancerFactory.kt index 7dec3d3..9eea113 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/enhancer/DashBoardApiEnhancerFactory.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/enhancer/DashBoardApiEnhancerFactory.kt @@ -39,7 +39,7 @@ class DashBoardApiEnhancerFactory( HibernateResourceEnhancer( config.database.copy( managedClasses = listOf( - Observation::class.jvmName + Observation::class.jvmName, ), ), ), diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/enhancer/DashboardApiEnhancer.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/enhancer/DashboardApiEnhancer.kt index 42f8108..6e806b4 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/enhancer/DashboardApiEnhancer.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/enhancer/DashboardApiEnhancer.kt @@ -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 @@ -51,6 +51,5 @@ class DashboardApiEnhancer( bind(ObservationRepository::class.java) .to(ObservationRepository::class.java) .`in`(Singleton::class.java) - } } diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/resource/ObservationResource.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/resource/ObservationResource.kt index 3e3d4b9..ff6d948 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/resource/ObservationResource.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/resource/ObservationResource.kt @@ -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 @@ -37,7 +42,7 @@ 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") @@ -45,7 +50,7 @@ class ObservationResource( 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 diff --git a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/service/ObservationService.kt b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/service/ObservationService.kt index 9f5874c..e2bc479 100644 --- a/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/service/ObservationService.kt +++ b/data-dashboard-backend/src/main/java/org/radarbase/datadashboard/api/service/ObservationService.kt @@ -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) diff --git a/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/DashboardIntegrationTest.kt b/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/DashboardIntegrationTest.kt index b73e411..d1dd263 100644 --- a/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/DashboardIntegrationTest.kt +++ b/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/DashboardIntegrationTest.kt @@ -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 @@ -85,5 +84,4 @@ class DashboardIntegrationTest: JerseyTest() { } // TODO add more tests that include the token validation. - } diff --git a/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/resource/ObservationResourceTest.kt b/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/resource/ObservationResourceTest.kt index 333fa1d..a3e007e 100644 --- a/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/resource/ObservationResourceTest.kt +++ b/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/resource/ObservationResourceTest.kt @@ -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 @@ -109,8 +109,7 @@ class ObservationResourceTest: JerseyTest() { date = ZonedDateTime.now(), valueTextual = "value1", valueNumeric = null, - endDate = null + endDate = null, ) } - -} \ No newline at end of file +} diff --git a/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/service/ObservationServiceTest.kt b/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/service/ObservationServiceTest.kt index aab6da5..8c86c53 100644 --- a/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/service/ObservationServiceTest.kt +++ b/data-dashboard-backend/src/test/java/org/radarbase/datadashboard/api/service/ObservationServiceTest.kt @@ -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 = listOf(createObservation(), createObservation(), createObservation(), createObservation()) @@ -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) } @@ -82,8 +81,7 @@ class ObservationServiceTest { date = ZonedDateTime.now(), valueTextual = "value1", valueNumeric = null, - endDate = null + endDate = null, ) } - -} \ No newline at end of file +}