Skip to content

Commit

Permalink
spotless apply to correct indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnasam committed Sep 8, 2024
1 parent 5b8d579 commit 76e0531
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package nz.govt.eop.plan_limits

import mu.KotlinLogging
import java.time.LocalDate
import java.time.temporal.ChronoUnit.YEARS
import java.util.concurrent.TimeUnit
import mu.KotlinLogging
import org.jooq.*
import org.springframework.http.CacheControl
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
Expand All @@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.ResponseBody

@Controller
class Controller(val context: DSLContext, val queries: Queries, val manifest: Manifest) {
private val logger = KotlinLogging.logger {}
private val logger = KotlinLogging.logger {}

@RequestMapping("/plan-limits/manifest", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
Expand Down Expand Up @@ -71,42 +71,42 @@ class Controller(val context: DSLContext, val queries: Queries, val manifest: Ma
@GetMapping("/plan-limits/surface-water-pnrp", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
fun surfaceWaterPNRP(@RequestParam(name = "councilId") councilId: Int): ResponseEntity<String> {
return try {
val result = queries.surfaceWaterPNRP(councilId)

// Check if the result is empty or null and handle it
if (result.isEmpty()) {
ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found for the given council ID.")
} else {
ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS))
.body(result)
}
} catch (e: Exception) {
logger.error("Error fetching surface water PNRP data", e)
// Return a generic Internal Server Error
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An unexpected error occurred while processing your request. Please try again later.")
return try {
val result = queries.surfaceWaterPNRP(councilId)

// Check if the result is empty or null and handle it
if (result.isEmpty()) {
ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found for the given council ID.")
} else {
ResponseEntity.ok().cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)).body(result)
}
} catch (e: Exception) {
logger.error("Error fetching surface water PNRP data", e)
// Return a generic Internal Server Error
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(
"An unexpected error occurred while processing your request. Please try again later.")
}
}

@GetMapping("/plan-limits/ground-water-pnrp", produces = [MediaType.APPLICATION_JSON_VALUE])
@ResponseBody
fun groundWaterPNRP(@RequestParam(name = "councilId") councilId: Int): ResponseEntity<String> {
return try {
val result = queries.groundWaterPNRP(councilId)

// Check if the result is empty or null and handle it
if (result.isEmpty()) {
ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found for the given council ID.")
} else {
ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS))
.body(result)
}
val result = queries.groundWaterPNRP(councilId)

// Check if the result is empty or null and handle it
if (result.isEmpty()) {
ResponseEntity.status(HttpStatus.NOT_FOUND).body("No data found for the given council ID.")
} else {
ResponseEntity.ok().cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)).body(result)
}
} catch (e: Exception) {
logger.error("Error fetching ground water PNRP data", e)
// Return a generic Internal Server Error
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An unexpected error occurred while processing your request. Please try again later.")
logger.error("Error fetching ground water PNRP data", e)
// Return a generic Internal Server Error
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(
"An unexpected error occurred while processing your request. Please try again later.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ class Manifest(val queries: Queries, val context: DSLContext) {
"/plan-limits/surface-water-limits" to generateHash(queries.surfaceWaterLimits(councilId)),
"/plan-limits/ground-water-limits" to
generateHash(queries.groundwaterWaterLimits(councilId)),
"/plan-limits/surface-water-pnrp" to
generateHash(queries.surfaceWaterPNRP(councilId)),
"/plan-limits/ground-water-pnrp" to
generateHash(queries.groundWaterPNRP(councilId)),
"/plan-limits/surface-water-pnrp" to generateHash(queries.surfaceWaterPNRP(councilId)),
"/plan-limits/ground-water-pnrp" to generateHash(queries.groundWaterPNRP(councilId)),
"/plan-limits/flow-measurement-sites" to
generateHash(queries.flowMeasurementSites(councilId)),
"/plan-limits/flow-limits" to generateHash(queries.flowLimits(councilId)),
Expand Down
104 changes: 52 additions & 52 deletions packages/Manager/src/main/kotlin/nz/govt/eop/plan_limits/Queries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import java.time.LocalDate
import nz.govt.eop.si.jooq.tables.Councils.Companion.COUNCILS
import nz.govt.eop.si.jooq.tables.FlowLimits.Companion.FLOW_LIMITS
import nz.govt.eop.si.jooq.tables.FlowMeasurementSites.Companion.FLOW_MEASUREMENT_SITES
import nz.govt.eop.si.jooq.tables.GroundwaterAllocationLimitsByAreaAndCategory.Companion.GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY
import nz.govt.eop.si.jooq.tables.GroundwaterAreas.Companion.GROUNDWATER_AREAS
import nz.govt.eop.si.jooq.tables.GroundwaterLimits.Companion.GROUNDWATER_LIMITS
import nz.govt.eop.si.jooq.tables.PlanRegions.Companion.PLAN_REGIONS
import nz.govt.eop.si.jooq.tables.Plans.Companion.PLANS
import nz.govt.eop.si.jooq.tables.SurfaceWaterLimits.Companion.SURFACE_WATER_LIMITS
import nz.govt.eop.si.jooq.tables.SurfacewaterAllocationLimitsByAreaAndCategory.Companion.SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY
import nz.govt.eop.si.jooq.tables.WaterAllocationAndUsageByArea.Companion.WATER_ALLOCATION_AND_USAGE_BY_AREA
import nz.govt.eop.si.jooq.tables.WaterAllocationsByArea.Companion.WATER_ALLOCATIONS_BY_AREA
import nz.govt.eop.si.jooq.tables.GroundwaterAllocationLimitsByAreaAndCategory.Companion.GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY
import nz.govt.eop.si.jooq.tables.SurfacewaterAllocationLimitsByAreaAndCategory.Companion.SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY
import org.jooq.*
import org.jooq.impl.DSL
import org.jooq.impl.DSL.*
Expand Down Expand Up @@ -122,59 +122,59 @@ class Queries(@Autowired val context: DSLContext) {
return buildFeatureCollection(context, innerQuery)
}

fun surfaceWaterPNRP(councilId: Int): String {
val innerQuery =
select(
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.AREA_ID,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PLAN_REGION_ID,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_A,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_B,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.SURFACE_TAKE,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.TOTAL_ALLOCATION,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.ALLOCATION_LIMIT,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PNRP_ALLOCATION_PERCENTAGE,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.NAME)
.from(SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY)
.where(
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PLAN_REGION_ID.`in`(
select(PLAN_REGIONS.ID)
.from(PLAN_REGIONS)
.join(PLANS)
.on(PLAN_REGIONS.PLAN_ID.eq(PLANS.ID))
.where(PLANS.COUNCIL_ID.eq(councilId))))
val featureCollection: Field<JSONB> =
function("to_jsonb", JSONB::class.java, field("to_jsonb(inputs)"))
fun surfaceWaterPNRP(councilId: Int): String {
val innerQuery =
select(
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.AREA_ID,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PLAN_REGION_ID,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_A,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_B,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.SURFACE_TAKE,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.TOTAL_ALLOCATION,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.ALLOCATION_LIMIT,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PNRP_ALLOCATION_PERCENTAGE,
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.NAME)
.from(SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY)
.where(
SURFACEWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PLAN_REGION_ID.`in`(
select(PLAN_REGIONS.ID)
.from(PLAN_REGIONS)
.join(PLANS)
.on(PLAN_REGIONS.PLAN_ID.eq(PLANS.ID))
.where(PLANS.COUNCIL_ID.eq(councilId))))
val featureCollection: Field<JSONB> =
function("to_jsonb", JSONB::class.java, field("to_jsonb(inputs)"))

val result = context.select(featureCollection).from(innerQuery.asTable("inputs")).fetch()
return result.firstNotNullOf { it.value1().toString() }
}
val result = context.select(featureCollection).from(innerQuery.asTable("inputs")).fetch()
return result.firstNotNullOf { it.value1().toString() }
}

fun groundWaterPNRP(councilId: Int): String {
val innerQuery =
select(
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.AREA_ID,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PLAN_REGION_ID,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_B,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_BC,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_C,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.TOTAL_ALLOCATION,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.ALLOCATION_LIMIT,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PNRP_ALLOCATION_PERCENTAGE,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.NAME)
.from(GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY)
.where(
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PLAN_REGION_ID.`in`(
select(PLAN_REGIONS.ID)
.from(PLAN_REGIONS)
.join(PLANS)
.on(PLAN_REGIONS.PLAN_ID.eq(PLANS.ID))
.where(PLANS.COUNCIL_ID.eq(councilId))))
val featureCollection: Field<JSONB> =
function("to_jsonb", JSONB::class.java, field("to_jsonb(inputs)"))
fun groundWaterPNRP(councilId: Int): String {
val innerQuery =
select(
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.AREA_ID,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PLAN_REGION_ID,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_B,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_BC,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.CATEGORY_C,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.TOTAL_ALLOCATION,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.ALLOCATION_LIMIT,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PNRP_ALLOCATION_PERCENTAGE,
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.NAME)
.from(GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY)
.where(
GROUNDWATER_ALLOCATION_LIMITS_BY_AREA_AND_CATEGORY.PLAN_REGION_ID.`in`(
select(PLAN_REGIONS.ID)
.from(PLAN_REGIONS)
.join(PLANS)
.on(PLAN_REGIONS.PLAN_ID.eq(PLANS.ID))
.where(PLANS.COUNCIL_ID.eq(councilId))))
val featureCollection: Field<JSONB> =
function("to_jsonb", JSONB::class.java, field("to_jsonb(inputs)"))

val result = context.select(featureCollection).from(innerQuery.asTable("inputs")).fetch()
return result.firstNotNullOf { it.value1().toString() }
}
val result = context.select(featureCollection).from(innerQuery.asTable("inputs")).fetch()
return result.firstNotNullOf { it.value1().toString() }
}

fun flowMeasurementSites(councilId: Int): String {
val innerQuery =
Expand Down

0 comments on commit 76e0531

Please sign in to comment.