From a4dbf4e1c0a396680672fe6a1827ef8d80e8988c Mon Sep 17 00:00:00 2001 From: Steven Grimm <1248649+sgrimm@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:43:28 -0800 Subject: [PATCH] SW-6348 Add monitoring plot numbers to search API (#2695) Add a search field for monitoring plot numbers. Since monitoring plots are now directly associated with their organizations in order to enforce uniqueness of plot numbers, the permission filter on the monitoring plots search table no longer needs to join to other tables. --- .../backend/search/table/MonitoringPlotsTable.kt | 12 +++++------- src/main/resources/i18n/Messages_en.properties | 1 + .../backend/tracking/TrackingSearchTest.kt | 5 +++++ 3 files changed, 11 insertions(+), 7 deletions(-) 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 f6fd0b01886..894c824ee01 100644 --- a/src/main/kotlin/com/terraformation/backend/search/table/MonitoringPlotsTable.kt +++ b/src/main/kotlin/com/terraformation/backend/search/table/MonitoringPlotsTable.kt @@ -1,5 +1,6 @@ package com.terraformation.backend.search.table +import com.terraformation.backend.auth.currentUser import com.terraformation.backend.db.tracking.MonitoringPlotId import com.terraformation.backend.db.tracking.tables.references.MONITORING_PLOTS import com.terraformation.backend.db.tracking.tables.references.PLANTING_SITE_SUMMARIES @@ -9,8 +10,8 @@ import com.terraformation.backend.search.SublistField import com.terraformation.backend.search.field.CoordinateField.Companion.LATITUDE import com.terraformation.backend.search.field.CoordinateField.Companion.LONGITUDE import com.terraformation.backend.search.field.SearchField +import org.jooq.Condition import org.jooq.Record -import org.jooq.SelectJoinStep import org.jooq.TableField class MonitoringPlotsTable(tables: SearchTables) : SearchTable() { @@ -42,6 +43,7 @@ class MonitoringPlotsTable(tables: SearchTables) : SearchTable() { coordinateField("northeastLongitude", MONITORING_PLOTS.BOUNDARY, NORTHEAST, LONGITUDE), coordinateField("northwestLatitude", MONITORING_PLOTS.BOUNDARY, NORTHWEST, LATITUDE), coordinateField("northwestLongitude", MONITORING_PLOTS.BOUNDARY, NORTHWEST, LONGITUDE), + longField("plotNumber", MONITORING_PLOTS.PLOT_NUMBER), integerField("sizeMeters", MONITORING_PLOTS.SIZE_METERS), coordinateField("southeastLatitude", MONITORING_PLOTS.BOUNDARY, SOUTHEAST, LATITUDE), coordinateField("southeastLongitude", MONITORING_PLOTS.BOUNDARY, SOUTHEAST, LONGITUDE), @@ -49,12 +51,8 @@ class MonitoringPlotsTable(tables: SearchTables) : SearchTable() { coordinateField("southwestLongitude", MONITORING_PLOTS.BOUNDARY, SOUTHWEST, LONGITUDE), ) - override val inheritsVisibilityFrom: SearchTable = tables.plantingSites - - override fun joinForVisibility(query: SelectJoinStep): SelectJoinStep { - return query - .join(PLANTING_SITE_SUMMARIES) - .on(MONITORING_PLOTS.PLANTING_SITE_ID.eq(PLANTING_SITE_SUMMARIES.ID)) + override fun conditionForVisibility(): Condition { + return MONITORING_PLOTS.ORGANIZATION_ID.`in`(currentUser().organizationRoles.keys) } companion object { diff --git a/src/main/resources/i18n/Messages_en.properties b/src/main/resources/i18n/Messages_en.properties index 65a05268f43..74428e30b81 100644 --- a/src/main/resources/i18n/Messages_en.properties +++ b/src/main/resources/i18n/Messages_en.properties @@ -545,6 +545,7 @@ search.monitoringPlots.northeastLatitude=Northeast corner latitude search.monitoringPlots.northeastLongitude=Northeast corner longitude search.monitoringPlots.northwestLatitude=Northwest corner latitude search.monitoringPlots.northwestLongitude=Northwest corner longitude +search.monitoringPlots.plotNumber=Monitoring plot number search.monitoringPlots.sizeMeters=Monitoring plot size (m) search.monitoringPlots.southeastLatitude=Southeast corner latitude search.monitoringPlots.southeastLongitude=Southeast corner longitude diff --git a/src/test/kotlin/com/terraformation/backend/tracking/TrackingSearchTest.kt b/src/test/kotlin/com/terraformation/backend/tracking/TrackingSearchTest.kt index 114cb003046..5a761ca245f 100644 --- a/src/test/kotlin/com/terraformation/backend/tracking/TrackingSearchTest.kt +++ b/src/test/kotlin/com/terraformation/backend/tracking/TrackingSearchTest.kt @@ -333,6 +333,7 @@ class TrackingSearchTest : DatabaseTest(), RunsAsUser { "northeastLongitude" to "7", "northwestLatitude" to "8", "northwestLongitude" to "5", + "plotNumber" to "1", "sizeMeters" to "30", "southeastLatitude" to "6", "southeastLongitude" to "7", @@ -345,6 +346,7 @@ class TrackingSearchTest : DatabaseTest(), RunsAsUser { "northeastLongitude" to "8", "northwestLatitude" to "9", "northwestLongitude" to "6", + "plotNumber" to "2", "sizeMeters" to "30", "southeastLatitude" to "7", "southeastLongitude" to "8", @@ -381,6 +383,7 @@ class TrackingSearchTest : DatabaseTest(), RunsAsUser { "northeastLongitude" to "9", "northwestLatitude" to "10", "northwestLongitude" to "7", + "plotNumber" to "3", "sizeMeters" to "30", "southeastLatitude" to "8", "southeastLongitude" to "9", @@ -393,6 +396,7 @@ class TrackingSearchTest : DatabaseTest(), RunsAsUser { "northeastLongitude" to "10", "northwestLatitude" to "11.01234568", "northwestLongitude" to "8", + "plotNumber" to "4", "sizeMeters" to "25", "southeastLatitude" to "9", "southeastLongitude" to "10", @@ -492,6 +496,7 @@ class TrackingSearchTest : DatabaseTest(), RunsAsUser { "plantingZones.plantingSubzones.monitoringPlots.northeastLongitude", "plantingZones.plantingSubzones.monitoringPlots.northwestLatitude", "plantingZones.plantingSubzones.monitoringPlots.northwestLongitude", + "plantingZones.plantingSubzones.monitoringPlots.plotNumber", "plantingZones.plantingSubzones.monitoringPlots.sizeMeters", "plantingZones.plantingSubzones.monitoringPlots.southeastLatitude", "plantingZones.plantingSubzones.monitoringPlots.southeastLongitude",