Skip to content

Commit

Permalink
Implement is_ad_hoc and observation_type_id into pre-existing observa…
Browse files Browse the repository at this point in the history
…tion code
  • Loading branch information
Nick Graziano committed Nov 26, 2024
1 parent e4b5bac commit 9130483
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.terraformation.backend.db.default_schema.tables.daos.OrganizationsDao
import com.terraformation.backend.db.tracking.MonitoringPlotId
import com.terraformation.backend.db.tracking.ObservationId
import com.terraformation.backend.db.tracking.ObservationState
import com.terraformation.backend.db.tracking.ObservationType
import com.terraformation.backend.db.tracking.PlantingSeasonId
import com.terraformation.backend.db.tracking.PlantingSiteId
import com.terraformation.backend.db.tracking.PlantingSubzoneId
Expand Down Expand Up @@ -691,6 +692,8 @@ class AdminPlantingSitesController(
NewObservationModel(
endDate = LocalDate.parse(endDate),
id = null,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSiteId,
requestedSubzoneIds = requestedSubzoneIds ?: emptySet(),
startDate = LocalDate.parse(startDate),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.terraformation.backend.db.tracking.ObservationId
import com.terraformation.backend.db.tracking.ObservationPlotPosition
import com.terraformation.backend.db.tracking.ObservationPlotStatus
import com.terraformation.backend.db.tracking.ObservationState
import com.terraformation.backend.db.tracking.ObservationType
import com.terraformation.backend.db.tracking.PlantingSiteId
import com.terraformation.backend.db.tracking.PlantingSubzoneId
import com.terraformation.backend.db.tracking.PlantingZoneId
Expand Down Expand Up @@ -998,6 +999,8 @@ data class ScheduleObservationRequestPayload(
NewObservationModel(
endDate = endDate,
id = null,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSiteId,
requestedSubzoneIds = requestedSubzoneIds ?: emptySet(),
startDate = startDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ class ObservationStore(
ObservationsRow(
createdTime = clock.instant(),
endDate = newModel.endDate,
isAdHoc = newModel.isAdHoc,
observationTypeId = newModel.observationType,
plantingSiteId = newModel.plantingSiteId,
startDate = newModel.startDate,
stateId = ObservationState.Upcoming,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.terraformation.backend.tracking.model

import com.terraformation.backend.db.tracking.ObservationId
import com.terraformation.backend.db.tracking.ObservationState
import com.terraformation.backend.db.tracking.ObservationType
import com.terraformation.backend.db.tracking.PlantingSiteId
import com.terraformation.backend.db.tracking.PlantingSubzoneId
import com.terraformation.backend.db.tracking.tables.references.OBSERVATIONS
Expand All @@ -14,6 +15,8 @@ data class ObservationModel<ID : ObservationId?>(
val completedTime: Instant? = null,
val endDate: LocalDate,
val id: ID,
val isAdHoc: Boolean,
val observationType: ObservationType,
val plantingSiteId: PlantingSiteId,
val requestedSubzoneIds: Set<PlantingSubzoneId> = emptySet(),
val startDate: LocalDate,
Expand Down Expand Up @@ -46,6 +49,8 @@ data class ObservationModel<ID : ObservationId?>(
completedTime = record[OBSERVATIONS.COMPLETED_TIME],
endDate = record[OBSERVATIONS.END_DATE]!!,
id = record[OBSERVATIONS.ID]!!,
isAdHoc = record[OBSERVATIONS.IS_AD_HOC]!!,
observationType = record[OBSERVATIONS.OBSERVATION_TYPE_ID]!!,
plantingSiteId = record[OBSERVATIONS.PLANTING_SITE_ID]!!,
requestedSubzoneIds = record[requestedSubzoneIdsField],
startDate = record[OBSERVATIONS.START_DATE]!!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.terraformation.backend.db.default_schema.tables.pojos.NotificationsRo
import com.terraformation.backend.db.docprod.VariableType
import com.terraformation.backend.db.nursery.tables.pojos.BatchesRow
import com.terraformation.backend.db.tracking.ObservationState
import com.terraformation.backend.db.tracking.ObservationType
import com.terraformation.backend.device.db.DeviceStore
import com.terraformation.backend.device.event.DeviceUnresponsiveEvent
import com.terraformation.backend.device.event.SensorBoundsAlertTriggeredEvent
Expand Down Expand Up @@ -509,6 +510,8 @@ internal class AppNotificationServiceTest : DatabaseTest(), RunsAsUser {
ExistingObservationModel(
endDate = endDate,
id = inserted.observationId,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = inserted.plantingSiteId,
startDate = startDate,
state = ObservationState.InProgress)))
Expand Down Expand Up @@ -540,6 +543,8 @@ internal class AppNotificationServiceTest : DatabaseTest(), RunsAsUser {
ExistingObservationModel(
endDate = endDate,
id = inserted.observationId,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = inserted.plantingSiteId,
startDate = startDate,
state = ObservationState.Upcoming)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ import com.terraformation.backend.db.tracking.ObservationId
import com.terraformation.backend.db.tracking.ObservationPlotPosition
import com.terraformation.backend.db.tracking.ObservationPlotStatus
import com.terraformation.backend.db.tracking.ObservationState
import com.terraformation.backend.db.tracking.ObservationType
import com.terraformation.backend.db.tracking.ObservedPlotCoordinatesId
import com.terraformation.backend.db.tracking.PlantingId
import com.terraformation.backend.db.tracking.PlantingSeasonId
Expand Down Expand Up @@ -2237,6 +2238,8 @@ abstract class DatabaseBackedTest {
row: ObservationsRow = ObservationsRow(),
createdTime: Instant = Instant.EPOCH,
endDate: LocalDate = row.endDate ?: LocalDate.of(2023, 1, 31),
isAdHoc: Boolean = row.isAdHoc ?: false,
observationType: ObservationType = row.observationTypeId ?: ObservationType.Monitoring,
plantingSiteId: PlantingSiteId = row.plantingSiteId ?: inserted.plantingSiteId,
startDate: LocalDate = row.startDate ?: LocalDate.of(2023, 1, 1),
completedTime: Instant? = row.completedTime,
Expand All @@ -2254,6 +2257,8 @@ abstract class DatabaseBackedTest {
completedTime = completedTime,
createdTime = createdTime,
endDate = endDate,
isAdHoc = isAdHoc,
observationTypeId = observationType,
plantingSiteId = plantingSiteId,
startDate = startDate,
stateId = state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import com.terraformation.backend.db.seedbank.AccessionId
import com.terraformation.backend.db.tracking.MonitoringPlotId
import com.terraformation.backend.db.tracking.ObservationId
import com.terraformation.backend.db.tracking.ObservationState
import com.terraformation.backend.db.tracking.ObservationType
import com.terraformation.backend.db.tracking.PlantingSeasonId
import com.terraformation.backend.db.tracking.PlantingSiteId
import com.terraformation.backend.device.db.DeviceStore
Expand Down Expand Up @@ -277,6 +278,8 @@ internal class EmailNotificationServiceTest {
ExistingObservationModel(
endDate = LocalDate.of(2023, 9, 30),
id = ObservationId(1),
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSite.id,
startDate = LocalDate.of(2023, 9, 1),
state = ObservationState.Upcoming)
Expand Down Expand Up @@ -564,6 +567,8 @@ internal class EmailNotificationServiceTest {
ExistingObservationModel(
endDate = LocalDate.of(2023, 9, 30),
id = ObservationId(1),
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSite.id,
startDate = LocalDate.of(2023, 9, 1),
state = ObservationState.InProgress))
Expand Down Expand Up @@ -626,6 +631,8 @@ internal class EmailNotificationServiceTest {
ExistingObservationModel(
endDate = LocalDate.of(2023, 10, 31),
id = ObservationId(1),
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSite.id,
startDate = LocalDate.of(2023, 10, 1),
state = ObservationState.Upcoming))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.terraformation.backend.db.tracking.MonitoringPlotId
import com.terraformation.backend.db.tracking.ObservationId
import com.terraformation.backend.db.tracking.ObservationPlotPosition
import com.terraformation.backend.db.tracking.ObservationState
import com.terraformation.backend.db.tracking.ObservationType
import com.terraformation.backend.db.tracking.PlantingSiteId
import com.terraformation.backend.db.tracking.PlantingSubzoneId
import com.terraformation.backend.db.tracking.RecordedSpeciesCertainty.Known
Expand Down Expand Up @@ -928,6 +929,8 @@ class ObservationServiceTest : DatabaseTest(), RunsAsDatabaseUser {
NewObservationModel(
plantingSiteId = plantingSiteId,
id = null,
isAdHoc = false,
observationType = ObservationType.Monitoring,
startDate = startDate,
endDate = endDate,
state = ObservationState.Upcoming,
Expand Down Expand Up @@ -1740,6 +1743,8 @@ class ObservationServiceTest : DatabaseTest(), RunsAsDatabaseUser {
ExistingObservationModel(
endDate = LocalDate.of(2023, 1, 31),
id = observationId,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = inserted.plantingSiteId,
startDate = LocalDate.of(2023, 1, 1),
state = ObservationState.InProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.terraformation.backend.db.tracking.ObservationId
import com.terraformation.backend.db.tracking.ObservationPlotPosition
import com.terraformation.backend.db.tracking.ObservationPlotStatus
import com.terraformation.backend.db.tracking.ObservationState
import com.terraformation.backend.db.tracking.ObservationType
import com.terraformation.backend.db.tracking.PlantingSiteId
import com.terraformation.backend.db.tracking.PlantingZoneId
import com.terraformation.backend.db.tracking.RecordedPlantStatus.Dead
Expand Down Expand Up @@ -132,6 +133,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser {
ExistingObservationModel(
endDate = endDate1,
id = observationId2,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSiteId,
requestedSubzoneIds = setOf(subzoneId),
startDate = startDate1,
Expand All @@ -140,6 +143,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser {
ExistingObservationModel(
endDate = endDate2,
id = observationId1,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSiteId,
startDate = startDate2,
state = ObservationState.Upcoming,
Expand Down Expand Up @@ -609,6 +614,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser {
completedTime = Instant.EPOCH,
endDate = LocalDate.of(2020, 1, 31),
id = null,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSiteId,
requestedSubzoneIds = setOf(subzoneId1, subzoneId2),
startDate = LocalDate.of(2020, 1, 1),
Expand All @@ -622,6 +629,7 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser {
endDate = LocalDate.of(2020, 1, 31),
id = observationId,
isAdHoc = false,
observationTypeId = ObservationType.Monitoring,
plantingSiteId = plantingSiteId,
startDate = LocalDate.of(2020, 1, 1),
stateId = ObservationState.Upcoming,
Expand All @@ -648,6 +656,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser {
NewObservationModel(
endDate = LocalDate.of(2020, 1, 31),
id = null,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSiteId,
requestedSubzoneIds = setOf(otherSiteSubzoneId),
startDate = LocalDate.of(2020, 1, 1),
Expand All @@ -665,6 +675,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser {
NewObservationModel(
endDate = LocalDate.EPOCH,
id = null,
isAdHoc = false,
observationType = ObservationType.Monitoring,
plantingSiteId = plantingSiteId,
startDate = LocalDate.EPOCH,
state = ObservationState.Upcoming,
Expand Down

0 comments on commit 9130483

Please sign in to comment.