From 88ebbcd4e81fda4fc81e07806d6d4874986e0e92 Mon Sep 17 00:00:00 2001 From: Tommy Lau <8563294+tommylau523@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:14:30 -0800 Subject: [PATCH] SW-6282 Added isAdHoc flag and ObservationType to observation and monitoring plot tables (#2681) --- .../com/terraformation/backend/jooq/Config.kt | 4 +++ .../admin/AdminPlantingSitesController.kt | 3 +++ .../search/table/MonitoringPlotsTable.kt | 2 ++ .../backend/search/table/ObservationsTable.kt | 2 ++ .../tracking/api/ObservationsController.kt | 3 +++ .../backend/tracking/db/ObservationStore.kt | 2 ++ .../backend/tracking/db/PlantingSiteStore.kt | 10 ++++++- .../tracking/model/MonitoringPlotModel.kt | 2 ++ .../tracking/model/ObservationModel.kt | 5 ++++ .../db/migration/0300/V326__AdHocPlots.sql | 27 +++++++++++++++++++ .../resources/db/migration/R__Comments.sql | 2 ++ .../resources/db/migration/R__TypeCodes.sql | 5 ++++ src/main/resources/i18n/Enums_en.properties | 2 ++ .../resources/i18n/Messages_en.properties | 4 +++ .../customer/AppNotificationServiceTest.kt | 5 ++++ .../backend/db/DatabaseBackedTest.kt | 7 +++++ .../backend/db/SchemaDocsGenerator.kt | 1 + .../email/EmailNotificationServiceTest.kt | 7 +++++ .../tracking/ObservationServiceTest.kt | 5 ++++ .../tracking/db/ObservationStoreTest.kt | 13 +++++++++ .../PlantingSiteStoreCreateTemporaryTest.kt | 1 + .../PlantingSiteStoreFetchSiteTest.kt | 6 +++++ .../tracking/model/PlantingSiteBuilder.kt | 1 + .../tracking/model/PlantingZoneModelTest.kt | 1 + 24 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/db/migration/0300/V326__AdHocPlots.sql diff --git a/jooq/src/main/kotlin/com/terraformation/backend/jooq/Config.kt b/jooq/src/main/kotlin/com/terraformation/backend/jooq/Config.kt index c67f80011c61..de2d70e66494 100644 --- a/jooq/src/main/kotlin/com/terraformation/backend/jooq/Config.kt +++ b/jooq/src/main/kotlin/com/terraformation/backend/jooq/Config.kt @@ -171,6 +171,7 @@ val ENUM_TABLES = isLocalizable = false), EnumTable( "observation_states", listOf("observations\\.state_id"), isLocalizable = false), + EnumTable("observation_types", listOf("observations\\.observation_type_id")), EnumTable("planting_types"), EnumTable( "recorded_plant_statuses", @@ -317,6 +318,9 @@ val ID_WRAPPERS = listOf("monitoring_plot_histories\\.id", ".*\\.monitoring_plot_history_id")), IdWrapper("MonitoringPlotId", listOf("monitoring_plots\\.id", ".*\\..*_plot_id")), IdWrapper("ObservationId", listOf("observations\\.id", ".*\\.observation_id")), + IdWrapper( + "ObservationTypeId", + listOf("observation_types\\.id", ".*\\.observation_type_id")), IdWrapper("ObservedPlotCoordinatesId", listOf("observed_plot_coordinates\\.id")), IdWrapper("PlantingId", listOf("plantings\\.id")), IdWrapper("PlantingSeasonId", listOf("planting_seasons\\.id")), diff --git a/src/main/kotlin/com/terraformation/backend/admin/AdminPlantingSitesController.kt b/src/main/kotlin/com/terraformation/backend/admin/AdminPlantingSitesController.kt index 0ecaee7449b8..f94c9a5a86c4 100644 --- a/src/main/kotlin/com/terraformation/backend/admin/AdminPlantingSitesController.kt +++ b/src/main/kotlin/com/terraformation/backend/admin/AdminPlantingSitesController.kt @@ -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 @@ -699,6 +700,8 @@ class AdminPlantingSitesController( NewObservationModel( endDate = LocalDate.parse(endDate), id = null, + isAdHoc = false, + observationType = ObservationType.Monitoring, plantingSiteId = plantingSiteId, requestedSubzoneIds = requestedSubzoneIds ?: emptySet(), startDate = LocalDate.parse(startDate), diff --git a/src/main/kotlin/com/terraformation/backend/search/table/MonitoringPlotsTable.kt b/src/main/kotlin/com/terraformation/backend/search/table/MonitoringPlotsTable.kt index 1e7289ae2da5..f6fd0b01886c 100644 --- a/src/main/kotlin/com/terraformation/backend/search/table/MonitoringPlotsTable.kt +++ b/src/main/kotlin/com/terraformation/backend/search/table/MonitoringPlotsTable.kt @@ -34,6 +34,8 @@ class MonitoringPlotsTable(tables: SearchTables) : SearchTable() { timestampField("createdTime", MONITORING_PLOTS.CREATED_TIME), textField("fullName", MONITORING_PLOTS.FULL_NAME), idWrapperField("id", MONITORING_PLOTS.ID) { MonitoringPlotId(it) }, + booleanField("isAdHoc", MONITORING_PLOTS.IS_AD_HOC), + booleanField("isAvailable", MONITORING_PLOTS.IS_AVAILABLE), timestampField("modifiedTime", MONITORING_PLOTS.MODIFIED_TIME), textField("name", MONITORING_PLOTS.NAME), coordinateField("northeastLatitude", MONITORING_PLOTS.BOUNDARY, NORTHEAST, LATITUDE), diff --git a/src/main/kotlin/com/terraformation/backend/search/table/ObservationsTable.kt b/src/main/kotlin/com/terraformation/backend/search/table/ObservationsTable.kt index 3850783a82de..80a47974a6fb 100644 --- a/src/main/kotlin/com/terraformation/backend/search/table/ObservationsTable.kt +++ b/src/main/kotlin/com/terraformation/backend/search/table/ObservationsTable.kt @@ -33,10 +33,12 @@ class ObservationsTable(private val tables: SearchTables) : SearchTable() { timestampField("createdTime", OBSERVATIONS.CREATED_TIME), dateField("endDate", OBSERVATIONS.END_DATE), idWrapperField("id", OBSERVATIONS.ID) { ObservationId(it) }, + booleanField("isAdHoc", OBSERVATIONS.IS_AD_HOC), idWrapperField("plantingSiteHistoryId", OBSERVATIONS.PLANTING_SITE_HISTORY_ID) { PlantingSiteHistoryId(it) }, dateField("startDate", OBSERVATIONS.START_DATE), + enumField("type", OBSERVATIONS.OBSERVATION_TYPE_ID), ) override val inheritsVisibilityFrom: SearchTable diff --git a/src/main/kotlin/com/terraformation/backend/tracking/api/ObservationsController.kt b/src/main/kotlin/com/terraformation/backend/tracking/api/ObservationsController.kt index 918aab463d3d..2e6a0858f21c 100644 --- a/src/main/kotlin/com/terraformation/backend/tracking/api/ObservationsController.kt +++ b/src/main/kotlin/com/terraformation/backend/tracking/api/ObservationsController.kt @@ -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.PlantingSiteHistoryId import com.terraformation.backend.db.tracking.PlantingSiteId import com.terraformation.backend.db.tracking.PlantingSubzoneId @@ -1012,6 +1013,8 @@ data class ScheduleObservationRequestPayload( NewObservationModel( endDate = endDate, id = null, + isAdHoc = false, + observationType = ObservationType.Monitoring, plantingSiteId = plantingSiteId, requestedSubzoneIds = requestedSubzoneIds ?: emptySet(), startDate = startDate, diff --git a/src/main/kotlin/com/terraformation/backend/tracking/db/ObservationStore.kt b/src/main/kotlin/com/terraformation/backend/tracking/db/ObservationStore.kt index 397645500972..74aabb55567d 100644 --- a/src/main/kotlin/com/terraformation/backend/tracking/db/ObservationStore.kt +++ b/src/main/kotlin/com/terraformation/backend/tracking/db/ObservationStore.kt @@ -431,6 +431,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, diff --git a/src/main/kotlin/com/terraformation/backend/tracking/db/PlantingSiteStore.kt b/src/main/kotlin/com/terraformation/backend/tracking/db/PlantingSiteStore.kt index 389bcdd15f73..37ebfb4cfa67 100644 --- a/src/main/kotlin/com/terraformation/backend/tracking/db/PlantingSiteStore.kt +++ b/src/main/kotlin/com/terraformation/backend/tracking/db/PlantingSiteStore.kt @@ -1576,6 +1576,7 @@ class PlantingSiteStore( createdBy = userId, createdTime = now, fullName = "${subzone.fullName}-$plotNumber", + isAdHoc = false, modifiedBy = userId, modifiedTime = now, name = "$plotNumber", @@ -1627,6 +1628,7 @@ class PlantingSiteStore( createdBy = userId, createdTime = now, fullName = "${subzone.fullName}-$plotNumber", + isAdHoc = false, modifiedBy = userId, modifiedTime = now, name = "$plotNumber", @@ -1703,6 +1705,7 @@ class PlantingSiteStore( DSL.select( MONITORING_PLOTS.ID, MONITORING_PLOTS.FULL_NAME, + MONITORING_PLOTS.IS_AD_HOC, MONITORING_PLOTS.IS_AVAILABLE, MONITORING_PLOTS.NAME, MONITORING_PLOTS.PERMANENT_CLUSTER, @@ -1717,6 +1720,7 @@ class PlantingSiteStore( MonitoringPlotModel( boundary = record[monitoringPlotBoundaryField]!! as Polygon, id = record[MONITORING_PLOTS.ID]!!, + isAdHoc = record[MONITORING_PLOTS.IS_AD_HOC]!!, isAvailable = record[MONITORING_PLOTS.IS_AVAILABLE]!!, fullName = record[MONITORING_PLOTS.FULL_NAME]!!, name = record[MONITORING_PLOTS.NAME]!!, @@ -1765,7 +1769,11 @@ class PlantingSiteStore( ): Field> { val plotsField = if (depth == PlantingSiteDepth.Plot) - monitoringPlotsMultiset(PLANTING_SUBZONES.ID.eq(MONITORING_PLOTS.PLANTING_SUBZONE_ID)) + monitoringPlotsMultiset( + DSL.and( + PLANTING_SUBZONES.ID.eq(MONITORING_PLOTS.PLANTING_SUBZONE_ID), + MONITORING_PLOTS.IS_AD_HOC.isFalse(), + )) else null return DSL.multiset( diff --git a/src/main/kotlin/com/terraformation/backend/tracking/model/MonitoringPlotModel.kt b/src/main/kotlin/com/terraformation/backend/tracking/model/MonitoringPlotModel.kt index 820722aa10ba..37ae959151b8 100644 --- a/src/main/kotlin/com/terraformation/backend/tracking/model/MonitoringPlotModel.kt +++ b/src/main/kotlin/com/terraformation/backend/tracking/model/MonitoringPlotModel.kt @@ -7,6 +7,7 @@ import org.locationtech.jts.geom.Polygon data class MonitoringPlotModel( val boundary: Polygon, val id: MonitoringPlotId, + val isAdHoc: Boolean, val isAvailable: Boolean, val fullName: String, val name: String, @@ -20,6 +21,7 @@ data class MonitoringPlotModel( fun equals(other: Any?, tolerance: Double): Boolean { return other is MonitoringPlotModel && id == other.id && + isAdHoc == other.isAdHoc && isAvailable == other.isAvailable && fullName == other.fullName && name == other.name && diff --git a/src/main/kotlin/com/terraformation/backend/tracking/model/ObservationModel.kt b/src/main/kotlin/com/terraformation/backend/tracking/model/ObservationModel.kt index 498d480e6d50..3f95efc4a2c7 100644 --- a/src/main/kotlin/com/terraformation/backend/tracking/model/ObservationModel.kt +++ b/src/main/kotlin/com/terraformation/backend/tracking/model/ObservationModel.kt @@ -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.PlantingSiteHistoryId import com.terraformation.backend.db.tracking.PlantingSiteId import com.terraformation.backend.db.tracking.PlantingSubzoneId @@ -15,6 +16,8 @@ data class ObservationModel( val completedTime: Instant? = null, val endDate: LocalDate, val id: ID, + val isAdHoc: Boolean, + val observationType: ObservationType, val plantingSiteHistoryId: PlantingSiteHistoryId? = null, val plantingSiteId: PlantingSiteId, val requestedSubzoneIds: Set = emptySet(), @@ -48,6 +51,8 @@ data class ObservationModel( 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]!!, plantingSiteHistoryId = record[OBSERVATIONS.PLANTING_SITE_HISTORY_ID], plantingSiteId = record[OBSERVATIONS.PLANTING_SITE_ID]!!, requestedSubzoneIds = record[requestedSubzoneIdsField], diff --git a/src/main/resources/db/migration/0300/V326__AdHocPlots.sql b/src/main/resources/db/migration/0300/V326__AdHocPlots.sql new file mode 100644 index 000000000000..78d3f3fc06a9 --- /dev/null +++ b/src/main/resources/db/migration/0300/V326__AdHocPlots.sql @@ -0,0 +1,27 @@ +CREATE TABLE tracking.observation_types ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL UNIQUE +); + +INSERT INTO tracking.observation_types (id, name) +VALUES (1, 'Monitoring'), + (2, 'Biomass Measurements') +ON CONFLICT (id) DO UPDATE SET name = excluded.name; + +ALTER TABLE tracking.observations ADD COLUMN observation_type_id INTEGER REFERENCES tracking.observation_types; +UPDATE tracking.observations +SET observation_type_id = 1 +WHERE observation_type_id IS NULL; +ALTER TABLE tracking.observations ALTER COLUMN observation_type_id SET NOT NULL; + +ALTER TABLE tracking.observations ADD COLUMN is_ad_hoc BOOLEAN; +UPDATE tracking.observations +SET is_ad_hoc = false +WHERE is_ad_hoc IS NULL; +ALTER TABLE tracking.observations ALTER COLUMN is_ad_hoc SET NOT NULL; + +ALTER TABLE tracking.monitoring_plots ADD COLUMN is_ad_hoc BOOLEAN; +UPDATE tracking.monitoring_plots +SET is_ad_hoc = false +WHERE is_ad_hoc IS NULL; +ALTER TABLE tracking.monitoring_plots ALTER COLUMN is_ad_hoc SET NOT NULL; diff --git a/src/main/resources/db/migration/R__Comments.sql b/src/main/resources/db/migration/R__Comments.sql index 8df3ddbba92e..ea6beba78927 100644 --- a/src/main/resources/db/migration/R__Comments.sql +++ b/src/main/resources/db/migration/R__Comments.sql @@ -381,6 +381,8 @@ COMMENT ON TABLE tracking.observation_requested_subzones IS 'If an observation s COMMENT ON TABLE tracking.observation_states IS '(Enum) Where in the observation lifecycle a particular observation is.'; +COMMENT ON TABLE tracking.observation_types IS '(Enum) Type of observation, currently only used for ad hoc observations.'; + COMMENT ON TABLE tracking.observations IS 'Scheduled observations of planting sites. This table may contain rows describing future observations as well as current and past ones.'; COMMENT ON COLUMN tracking.observations.completed_time IS 'Server-generated date and time the final piece of data for the observation was received.'; COMMENT ON COLUMN tracking.observations.end_date IS 'Last day of the observation. This is typically the last day of the same month as `start_date`.'; diff --git a/src/main/resources/db/migration/R__TypeCodes.sql b/src/main/resources/db/migration/R__TypeCodes.sql index db85e61c38d3..c557cc862396 100644 --- a/src/main/resources/db/migration/R__TypeCodes.sql +++ b/src/main/resources/db/migration/R__TypeCodes.sql @@ -348,6 +348,11 @@ VALUES (1, 'Upcoming'), (5, 'Abandoned') ON CONFLICT (id) DO UPDATE SET name = excluded.name; +INSERT INTO tracking.observation_types (id, name) +VALUES (1, 'Monitoring'), + (2, 'Biomass Measurements') +ON CONFLICT (id) DO UPDATE SET name = excluded.name; + INSERT INTO organization_types (id, name) VALUES (1, 'Government'), (2, 'NGO'), diff --git a/src/main/resources/i18n/Enums_en.properties b/src/main/resources/i18n/Enums_en.properties index ced335488304..ea6a0c92f61c 100644 --- a/src/main/resources/i18n/Enums_en.properties +++ b/src/main/resources/i18n/Enums_en.properties @@ -307,3 +307,5 @@ tracking.PlantingType.Delivery=Delivery tracking.PlantingType.ReassignmentFrom=Reassignment From tracking.PlantingType.ReassignmentTo=Reassignment To tracking.PlantingType.Undo=Undo +tracking.ObservationType.BiomassMeasurements=Biomass Measurements +tracking.ObservationType.Monitoring=Monitoring diff --git a/src/main/resources/i18n/Messages_en.properties b/src/main/resources/i18n/Messages_en.properties index fb20230cc35e..65a05268f43e 100644 --- a/src/main/resources/i18n/Messages_en.properties +++ b/src/main/resources/i18n/Messages_en.properties @@ -537,6 +537,8 @@ search.monitoringPlots.boundary=Monitoring plot boundary search.monitoringPlots.createdTime=Monitoring plot created time search.monitoringPlots.fullName=Monitoring plot full name search.monitoringPlots.id=Monitoring plot ID +search.monitoringPlots.isAdHoc=Monitoring plot is ad-hoc +search.monitoringPlots.isAvailable=Monitoring plot is available search.monitoringPlots.modifiedTime=Monitoring plot modified time search.monitoringPlots.name=Monitoring plot name search.monitoringPlots.northeastLatitude=Northeast corner latitude @@ -571,8 +573,10 @@ search.observations.completedTime=Observation completed time search.observations.createdTime=Observation created time search.observations.endDate=Observation end date search.observations.id=Observation ID +search.observations.isAdHoc=Observation is ad-hoc search.observations.plantingSiteHistoryId=Observation planting site history ID search.observations.startDate=Observation start date +search.observations.type=Observation type search.organizationInternalTags.name=Organization internal tag name search.organizationUsers.createdTime=Organization membership creation time search.organizationUsers.roleName=User role name diff --git a/src/test/kotlin/com/terraformation/backend/customer/AppNotificationServiceTest.kt b/src/test/kotlin/com/terraformation/backend/customer/AppNotificationServiceTest.kt index 9771d78003c8..256f12492f61 100644 --- a/src/test/kotlin/com/terraformation/backend/customer/AppNotificationServiceTest.kt +++ b/src/test/kotlin/com/terraformation/backend/customer/AppNotificationServiceTest.kt @@ -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 @@ -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))) @@ -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))) diff --git a/src/test/kotlin/com/terraformation/backend/db/DatabaseBackedTest.kt b/src/test/kotlin/com/terraformation/backend/db/DatabaseBackedTest.kt index 04cbc0039cc2..90dc17592fed 100644 --- a/src/test/kotlin/com/terraformation/backend/db/DatabaseBackedTest.kt +++ b/src/test/kotlin/com/terraformation/backend/db/DatabaseBackedTest.kt @@ -287,6 +287,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 @@ -1942,6 +1943,7 @@ abstract class DatabaseBackedTest { y.toDouble() * sizeMeters.toDouble()), createdBy: UserId = row.createdBy ?: currentUser().userId, createdTime: Instant = row.createdTime ?: Instant.EPOCH, + isAdHoc: Boolean = row.isAdHoc ?: false, isAvailable: Boolean = row.isAvailable ?: true, modifiedBy: UserId = row.modifiedBy ?: createdBy, modifiedTime: Instant = row.modifiedTime ?: createdTime, @@ -1961,6 +1963,7 @@ abstract class DatabaseBackedTest { createdBy = createdBy, createdTime = createdTime, fullName = fullName, + isAdHoc = isAdHoc, isAvailable = isAvailable, modifiedBy = modifiedBy, modifiedTime = modifiedTime, @@ -2276,6 +2279,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, @@ -2300,6 +2305,8 @@ abstract class DatabaseBackedTest { completedTime = completedTime, createdTime = createdTime, endDate = endDate, + isAdHoc = isAdHoc, + observationTypeId = observationType, plantingSiteHistoryId = plantingSiteHistoryId, plantingSiteId = plantingSiteId, startDate = startDate, diff --git a/src/test/kotlin/com/terraformation/backend/db/SchemaDocsGenerator.kt b/src/test/kotlin/com/terraformation/backend/db/SchemaDocsGenerator.kt index 442319dc6bd5..52aef09907fe 100644 --- a/src/test/kotlin/com/terraformation/backend/db/SchemaDocsGenerator.kt +++ b/src/test/kotlin/com/terraformation/backend/db/SchemaDocsGenerator.kt @@ -334,6 +334,7 @@ class SchemaDocsGenerator : DatabaseTest() { "observation_plots" to setOf(ALL, TRACKING), "observation_requested_subzones" to setOf(ALL, TRACKING), "observation_states" to setOf(ALL, TRACKING), + "observation_types" to setOf(ALL, TRACKING), "observations" to setOf(ALL, TRACKING), "observed_plot_coordinates" to setOf(ALL, TRACKING), "observed_plot_species_totals" to setOf(ALL, TRACKING), diff --git a/src/test/kotlin/com/terraformation/backend/email/EmailNotificationServiceTest.kt b/src/test/kotlin/com/terraformation/backend/email/EmailNotificationServiceTest.kt index 9981b09cf4d4..4e07a2ba4fc3 100644 --- a/src/test/kotlin/com/terraformation/backend/email/EmailNotificationServiceTest.kt +++ b/src/test/kotlin/com/terraformation/backend/email/EmailNotificationServiceTest.kt @@ -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 @@ -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) @@ -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)) @@ -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)) diff --git a/src/test/kotlin/com/terraformation/backend/tracking/ObservationServiceTest.kt b/src/test/kotlin/com/terraformation/backend/tracking/ObservationServiceTest.kt index be1a2124ec1d..a6b3f280e148 100644 --- a/src/test/kotlin/com/terraformation/backend/tracking/ObservationServiceTest.kt +++ b/src/test/kotlin/com/terraformation/backend/tracking/ObservationServiceTest.kt @@ -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 @@ -955,6 +956,8 @@ class ObservationServiceTest : DatabaseTest(), RunsAsDatabaseUser { NewObservationModel( plantingSiteId = plantingSiteId, id = null, + isAdHoc = false, + observationType = ObservationType.Monitoring, startDate = startDate, endDate = endDate, state = ObservationState.Upcoming, @@ -1767,6 +1770,8 @@ class ObservationServiceTest : DatabaseTest(), RunsAsDatabaseUser { ExistingObservationModel( endDate = LocalDate.of(2023, 1, 31), id = observationId, + isAdHoc = false, + observationType = ObservationType.Monitoring, plantingSiteHistoryId = inserted.plantingSiteHistoryId, plantingSiteId = inserted.plantingSiteId, startDate = LocalDate.of(2023, 1, 1), diff --git a/src/test/kotlin/com/terraformation/backend/tracking/db/ObservationStoreTest.kt b/src/test/kotlin/com/terraformation/backend/tracking/db/ObservationStoreTest.kt index f3670d281443..4eada78b1d98 100644 --- a/src/test/kotlin/com/terraformation/backend/tracking/db/ObservationStoreTest.kt +++ b/src/test/kotlin/com/terraformation/backend/tracking/db/ObservationStoreTest.kt @@ -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 @@ -137,6 +138,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser { ExistingObservationModel( endDate = endDate1, id = observationId2, + isAdHoc = false, + observationType = ObservationType.Monitoring, plantingSiteHistoryId = plantingSiteHistoryId, plantingSiteId = plantingSiteId, requestedSubzoneIds = setOf(subzoneId), @@ -146,6 +149,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser { ExistingObservationModel( endDate = endDate2, id = observationId1, + isAdHoc = false, + observationType = ObservationType.Monitoring, plantingSiteId = plantingSiteId, startDate = startDate2, state = ObservationState.Upcoming, @@ -615,6 +620,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), @@ -627,6 +634,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser { createdTime = clock.instant(), endDate = LocalDate.of(2020, 1, 31), id = observationId, + isAdHoc = false, + observationTypeId = ObservationType.Monitoring, plantingSiteId = plantingSiteId, startDate = LocalDate.of(2020, 1, 1), stateId = ObservationState.Upcoming, @@ -653,6 +662,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), @@ -670,6 +681,8 @@ class ObservationStoreTest : DatabaseTest(), RunsAsUser { NewObservationModel( endDate = LocalDate.EPOCH, id = null, + isAdHoc = false, + observationType = ObservationType.Monitoring, plantingSiteId = plantingSiteId, startDate = LocalDate.EPOCH, state = ObservationState.Upcoming, diff --git a/src/test/kotlin/com/terraformation/backend/tracking/db/plantingSiteStore/PlantingSiteStoreCreateTemporaryTest.kt b/src/test/kotlin/com/terraformation/backend/tracking/db/plantingSiteStore/PlantingSiteStoreCreateTemporaryTest.kt index e57659b27a60..395f8d581766 100644 --- a/src/test/kotlin/com/terraformation/backend/tracking/db/plantingSiteStore/PlantingSiteStoreCreateTemporaryTest.kt +++ b/src/test/kotlin/com/terraformation/backend/tracking/db/plantingSiteStore/PlantingSiteStoreCreateTemporaryTest.kt @@ -45,6 +45,7 @@ internal class PlantingSiteStoreCreateTemporaryTest : PlantingSiteStoreTest() { createdTime = clock.instant, fullName = "Z1-1-18", id = newPlotId, + isAdHoc = false, isAvailable = true, modifiedBy = user.userId, modifiedTime = clock.instant, diff --git a/src/test/kotlin/com/terraformation/backend/tracking/db/plantingSiteStore/PlantingSiteStoreFetchSiteTest.kt b/src/test/kotlin/com/terraformation/backend/tracking/db/plantingSiteStore/PlantingSiteStoreFetchSiteTest.kt index 61d9ecd69a84..d8f243f9bc3a 100644 --- a/src/test/kotlin/com/terraformation/backend/tracking/db/plantingSiteStore/PlantingSiteStoreFetchSiteTest.kt +++ b/src/test/kotlin/com/terraformation/backend/tracking/db/plantingSiteStore/PlantingSiteStoreFetchSiteTest.kt @@ -40,6 +40,9 @@ internal class PlantingSiteStoreFetchSiteTest : PlantingSiteStoreTest() { insertPlantingZone(boundary = multiPolygon(2.0), extraPermanentClusters = 1) val plantingSubzoneId = insertPlantingSubzone(boundary = multiPolygon(1.0)) val monitoringPlotId = insertMonitoringPlot(boundary = polygon(0.1)) + insertMonitoringPlot( + boundary = polygon(0.1), isAdHoc = true, name = "Ad hoc plot is not returned") + val season1StartDate = LocalDate.of(2023, 6, 1) val season1EndDate = LocalDate.of(2023, 7, 31) val plantingSeasonId1 = @@ -124,6 +127,7 @@ internal class PlantingSiteStoreFetchSiteTest : PlantingSiteStoreTest() { MonitoringPlotModel( boundary = polygon(0.2), id = exteriorPlotId, + isAdHoc = false, isAvailable = true, name = "2", fullName = "2", @@ -141,6 +145,7 @@ internal class PlantingSiteStoreFetchSiteTest : PlantingSiteStoreTest() { MonitoringPlotModel( boundary = polygon(0.1), id = monitoringPlotId, + isAdHoc = false, isAvailable = true, name = "1", fullName = "Z1-1-1", @@ -224,6 +229,7 @@ internal class PlantingSiteStoreFetchSiteTest : PlantingSiteStoreTest() { MonitoringPlotModel( boundary = monitoringPlotBoundary4326, id = monitoringPlotId, + isAdHoc = false, isAvailable = true, name = "1", fullName = "Z1-1-1", diff --git a/src/test/kotlin/com/terraformation/backend/tracking/model/PlantingSiteBuilder.kt b/src/test/kotlin/com/terraformation/backend/tracking/model/PlantingSiteBuilder.kt index c22ccccbfbf2..e96002e62795 100644 --- a/src/test/kotlin/com/terraformation/backend/tracking/model/PlantingSiteBuilder.kt +++ b/src/test/kotlin/com/terraformation/backend/tracking/model/PlantingSiteBuilder.kt @@ -255,6 +255,7 @@ private constructor( MonitoringPlotModel( boundary = rectanglePolygon(size, size, x, y), id = MonitoringPlotId(nextMonitoringPlotId++), + isAdHoc = false, isAvailable = isAvailable, fullName = "$fullName-$name", name = name, diff --git a/src/test/kotlin/com/terraformation/backend/tracking/model/PlantingZoneModelTest.kt b/src/test/kotlin/com/terraformation/backend/tracking/model/PlantingZoneModelTest.kt index c31ce6ce216a..0bcaefe8c69c 100644 --- a/src/test/kotlin/com/terraformation/backend/tracking/model/PlantingZoneModelTest.kt +++ b/src/test/kotlin/com/terraformation/backend/tracking/model/PlantingZoneModelTest.kt @@ -681,6 +681,7 @@ class PlantingZoneModelTest { return MonitoringPlotModel( boundary = boundary, id = MonitoringPlotId(id.toLong()), + isAdHoc = false, isAvailable = isAvailable, fullName = "name", name = "name",