From 89a088c4b31caefc62b75414fd75e6dcafd9f875 Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 15 Jun 2026 15:57:41 -0400 Subject: [PATCH] =?UTF-8?q?fix(aria):=20fix=20os=5Feol=5Fstatus=20enum=20c?= =?UTF-8?q?ast=20=E2=80=94=20use=20native=20SQL=20throughout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PostgreSQL named enum types require explicit casts that Hibernate's derived query methods don't generate. Replace countByOsEolStatus and findByOsEolStatusOrderByPostureScoreAsc with native @Query variants that CAST(:status AS os_eol_status). Same pattern already applied to severity. Co-Authored-By: Claude Sonnet 4.6 --- .../aria/controller/DevicePostureController.java | 2 +- .../aria/controller/ThreatEventController.java | 3 +-- .../repository/DeviceSecurityPostureRepository.java | 11 +++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/hiveops/aria/controller/DevicePostureController.java b/src/main/java/com/hiveops/aria/controller/DevicePostureController.java index 9b9e57d..a01dbd7 100644 --- a/src/main/java/com/hiveops/aria/controller/DevicePostureController.java +++ b/src/main/java/com/hiveops/aria/controller/DevicePostureController.java @@ -52,7 +52,7 @@ public class DevicePostureController { Pageable pageable = PageRequest.of(page, size); if (osEolStatus != null) { - return postureRepository.findByOsEolStatusOrderByPostureScoreAsc(osEolStatus, pageable); + return postureRepository.findByOsEolStatusNativeOrderByPostureScoreAsc(osEolStatus.name(), pageable); } if ("low".equals(scoreFilter)) { return postureRepository.findByPostureScoreLessThanOrderByPostureScoreAsc(50, pageable); diff --git a/src/main/java/com/hiveops/aria/controller/ThreatEventController.java b/src/main/java/com/hiveops/aria/controller/ThreatEventController.java index 9a65b75..29e706f 100644 --- a/src/main/java/com/hiveops/aria/controller/ThreatEventController.java +++ b/src/main/java/com/hiveops/aria/controller/ThreatEventController.java @@ -1,6 +1,5 @@ package com.hiveops.aria.controller; -import com.hiveops.aria.entity.DeviceSecurityPosture; import com.hiveops.aria.entity.ThreatEvent; import com.hiveops.aria.repository.DeviceSecurityPostureRepository; import com.hiveops.aria.repository.PrecursorSequenceAlertRepository; @@ -57,7 +56,7 @@ public class ThreatEventController { long activeSequences = sequenceAlertRepository.countByResolvedAtIsNull(); long lowPostureCount = postureRepository.countByPostureScoreLessThan(50); - long eolDeviceCount = postureRepository.countByOsEolStatus(DeviceSecurityPosture.OsEolStatus.EOL); + long eolDeviceCount = postureRepository.countByOsEolStatusNative("EOL"); return ResponseEntity.ok(Map.of( "totalEvents", totalEvents, diff --git a/src/main/java/com/hiveops/aria/repository/DeviceSecurityPostureRepository.java b/src/main/java/com/hiveops/aria/repository/DeviceSecurityPostureRepository.java index c96dd31..165419f 100644 --- a/src/main/java/com/hiveops/aria/repository/DeviceSecurityPostureRepository.java +++ b/src/main/java/com/hiveops/aria/repository/DeviceSecurityPostureRepository.java @@ -4,6 +4,8 @@ import com.hiveops.aria.entity.DeviceSecurityPosture; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -15,13 +17,14 @@ public interface DeviceSecurityPostureRepository extends JpaRepository findAllByOrderByPostureScoreAsc(Pageable pageable); - Page findByOsEolStatusOrderByPostureScoreAsc( - DeviceSecurityPosture.OsEolStatus osEolStatus, Pageable pageable); - Page findByPostureScoreLessThanOrderByPostureScoreAsc( int score, Pageable pageable); long countByPostureScoreLessThan(int score); - long countByOsEolStatus(DeviceSecurityPosture.OsEolStatus osEolStatus); + @Query(value = "SELECT COUNT(*) FROM device_security_posture WHERE os_eol_status = CAST(:status AS os_eol_status)", nativeQuery = true) + long countByOsEolStatusNative(@Param("status") String status); + + @Query(value = "SELECT * FROM device_security_posture WHERE os_eol_status = CAST(:status AS os_eol_status) ORDER BY posture_score ASC", nativeQuery = true, countQuery = "SELECT COUNT(*) FROM device_security_posture WHERE os_eol_status = CAST(:status AS os_eol_status)") + Page findByOsEolStatusNativeOrderByPostureScoreAsc(@Param("status") String status, Pageable pageable); }