Skip to content

Commit

Permalink
SW-6348 Add monitoring plot numbers to search API (#2695)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgrimm authored Dec 16, 2024
1 parent 52ae081 commit a4dbf4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -42,19 +43,16 @@ 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),
coordinateField("southwestLatitude", MONITORING_PLOTS.BOUNDARY, SOUTHWEST, LATITUDE),
coordinateField("southwestLongitude", MONITORING_PLOTS.BOUNDARY, SOUTHWEST, LONGITUDE),
)

override val inheritsVisibilityFrom: SearchTable = tables.plantingSites

override fun <T : Record> joinForVisibility(query: SelectJoinStep<T>): SelectJoinStep<T> {
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 {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/i18n/Messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit a4dbf4e

Please sign in to comment.