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); }