From 0918a08c9f86fc01a301dd06dbe7cda20f10a679 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Mon, 16 Sep 2024 13:06:24 +0200 Subject: [PATCH] Reformat for shorter line length --- .../io/gardenlinux/glvd/GlvdController.java | 30 +++++++++++---- .../java/io/gardenlinux/glvd/GlvdService.java | 28 +++++++++++--- .../io/gardenlinux/glvd/UiController.java | 16 ++++++-- .../glvd/db/SourcePackageCveRepository.java | 37 ++++++++++++++----- .../glvd/db/SourcePackageRepository.java | 6 ++- 5 files changed, 89 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/gardenlinux/glvd/GlvdController.java b/src/main/java/io/gardenlinux/glvd/GlvdController.java index f14a957..12d2c88 100644 --- a/src/main/java/io/gardenlinux/glvd/GlvdController.java +++ b/src/main/java/io/gardenlinux/glvd/GlvdController.java @@ -28,7 +28,9 @@ ResponseEntity> getCveDistro( @RequestParam(required = false) final String pageNumber, @RequestParam(required = false) final String pageSize ) { - return ResponseEntity.ok().body(glvdService.getCveForDistribution(gardenlinuxVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize))); + return ResponseEntity.ok().body(glvdService.getCveForDistribution( + gardenlinuxVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)) + ); } @GetMapping("/cves/{gardenlinuxVersion}/packages/{packageList}") @@ -40,7 +42,9 @@ ResponseEntity> getCvePackages( @RequestParam(required = false) final String pageNumber, @RequestParam(required = false) final String pageSize ) { - var cveForPackages = glvdService.getCveForPackages(gardenlinuxVersion, packageList, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)); + var cveForPackages = glvdService.getCveForPackages( + gardenlinuxVersion, packageList, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize) + ); return ResponseEntity.ok().body(cveForPackages); } @@ -54,7 +58,9 @@ ResponseEntity> getCvePackagesxx( @RequestParam(required = false) final String pageSize ) { var packageList = packages.toString(); - var cveForPackages = glvdService.getCveForPackages(gardenlinuxVersion, packageList, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)); + var cveForPackages = glvdService.getCveForPackages( + gardenlinuxVersion, packageList, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize) + ); return ResponseEntity.ok().body(cveForPackages); } @@ -66,7 +72,9 @@ ResponseEntity> packageWithVulnerabilities( @RequestParam(required = false) final String pageNumber, @RequestParam(required = false) final String pageSize ) { - return ResponseEntity.ok(glvdService.getPackageWithVulnerabilities(sourcePackage, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize))); + return ResponseEntity.ok( + glvdService.getPackageWithVulnerabilities(sourcePackage, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)) + ); } @GetMapping("/packages/{sourcePackage}/{sourcePackageVersion}") @@ -78,7 +86,11 @@ ResponseEntity> packageWithVulnerabilitiesByVersion( @RequestParam(required = false) final String pageNumber, @RequestParam(required = false) final String pageSize ) { - return ResponseEntity.ok(glvdService.getPackageWithVulnerabilitiesByVersion(sourcePackage, sourcePackageVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize))); + return ResponseEntity.ok( + glvdService.getPackageWithVulnerabilitiesByVersion( + sourcePackage, sourcePackageVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize) + ) + ); } @GetMapping("/distro/{gardenlinuxVersion}") @@ -89,7 +101,9 @@ ResponseEntity> packagesForDistro( @RequestParam(required = false) final String pageNumber, @RequestParam(required = false) final String pageSize ) { - return ResponseEntity.ok(glvdService.getPackagesForDistro(gardenlinuxVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize))); + return ResponseEntity.ok( + glvdService.getPackagesForDistro(gardenlinuxVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)) + ); } @GetMapping("/distro/{gardenlinuxVersion}/{cveId}") @@ -101,7 +115,9 @@ ResponseEntity> packagesByVulnerability( @RequestParam(required = false) final String pageNumber, @RequestParam(required = false) final String pageSize ) { - return ResponseEntity.ok(glvdService.getPackagesByVulnerability(gardenlinuxVersion, cveId, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize))); + return ResponseEntity.ok( + glvdService.getPackagesByVulnerability(gardenlinuxVersion, cveId, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)) + ); } } diff --git a/src/main/java/io/gardenlinux/glvd/GlvdService.java b/src/main/java/io/gardenlinux/glvd/GlvdService.java index e7b8d8e..0ac5354 100644 --- a/src/main/java/io/gardenlinux/glvd/GlvdService.java +++ b/src/main/java/io/gardenlinux/glvd/GlvdService.java @@ -64,27 +64,43 @@ private Pageable determinePageAndSortFeatures2(SortAndPageOptions sortAndPageOpt } public List getCveForDistribution(String gardenlinuxVersion, SortAndPageOptions sortAndPageOptions) { - return sourcePackageCveRepository.findByGardenlinuxVersion(gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions)); + return sourcePackageCveRepository.findByGardenlinuxVersion( + gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions) + ); + } + + private String wrap(String input) { + return "{" + input + "}"; } public List getCveForPackages(String gardenlinuxVersion, String packages, SortAndPageOptions sortAndPageOptions) { - return sourcePackageCveRepository.findBySourcePackageNameInAndGardenlinuxVersion("{" + packages + "}", gardenlinuxVersion, determinePageAndSortFeatures2(sortAndPageOptions)); + return sourcePackageCveRepository.findBySourcePackageNameInAndGardenlinuxVersion( + wrap(packages), gardenlinuxVersion, determinePageAndSortFeatures2(sortAndPageOptions) + ); } public List getPackagesForDistro(String gardenlinuxVersion, SortAndPageOptions sortAndPageOptions) { - return sourcePackageRepository.findByGardenlinuxVersion(gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions)); + return sourcePackageRepository.findByGardenlinuxVersion( + gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions) + ); } public List getPackageWithVulnerabilities(String sourcePackage, SortAndPageOptions sortAndPageOptions) { - return sourcePackageCveRepository.findBySourcePackageName(sourcePackage, determinePageAndSortFeatures(sortAndPageOptions)); + return sourcePackageCveRepository.findBySourcePackageName( + sourcePackage, determinePageAndSortFeatures(sortAndPageOptions) + ); } public List getPackageWithVulnerabilitiesByVersion(String sourcePackage, String sourcePackageVersion, SortAndPageOptions sortAndPageOptions) { - return sourcePackageCveRepository.findBySourcePackageNameAndSourcePackageVersion(sourcePackage, sourcePackageVersion, determinePageAndSortFeatures(sortAndPageOptions)); + return sourcePackageCveRepository.findBySourcePackageNameAndSourcePackageVersion( + sourcePackage, sourcePackageVersion, determinePageAndSortFeatures(sortAndPageOptions) + ); } public List getPackagesByVulnerability(String gardenlinuxVersion, String cveId, SortAndPageOptions sortAndPageOptions) { - return sourcePackageCveRepository.findByCveIdAndGardenlinuxVersion(cveId, gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions)); + return sourcePackageCveRepository.findByCveIdAndGardenlinuxVersion( + cveId, gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions) + ); } } diff --git a/src/main/java/io/gardenlinux/glvd/UiController.java b/src/main/java/io/gardenlinux/glvd/UiController.java index 339a43d..1adaa9f 100644 --- a/src/main/java/io/gardenlinux/glvd/UiController.java +++ b/src/main/java/io/gardenlinux/glvd/UiController.java @@ -24,7 +24,9 @@ public String getPackagesForDistro( @RequestParam(required = false) final String pageNumber, @RequestParam(required = false) final String pageSize, Model model) { - var packages = glvdService.getPackagesForDistro(gardenlinuxVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)); + var packages = glvdService.getPackagesForDistro( + gardenlinuxVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize) + ); model.addAttribute("packages", packages); model.addAttribute("gardenlinuxVersion", gardenlinuxVersion); return "getPackagesForDistro"; @@ -39,7 +41,9 @@ public String getCveForDistribution( @RequestParam(required = false) final String pageSize, Model model ) { - var sourcePackageCves = glvdService.getCveForDistribution(gardenlinuxVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)); + var sourcePackageCves = glvdService.getCveForDistribution( + gardenlinuxVersion, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize) + ); model.addAttribute("sourcePackageCves", sourcePackageCves); model.addAttribute("gardenlinuxVersion", gardenlinuxVersion); return "getCveForDistribution"; @@ -55,7 +59,9 @@ public String getCveForPackages( @RequestParam(required = false) final String pageSize, Model model ) { - var sourcePackageCves = glvdService.getCveForPackages(gardenlinuxVersion, packages, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)); + var sourcePackageCves = glvdService.getCveForPackages( + gardenlinuxVersion, packages, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize) + ); model.addAttribute("sourcePackageCves", sourcePackageCves); model.addAttribute("gardenlinuxVersion", gardenlinuxVersion); model.addAttribute("packages", packages); @@ -72,7 +78,9 @@ public String getPackagesByVulnerability( @RequestParam(required = false) final String pageSize, Model model ) { - var sourcePackageCves = glvdService.getPackagesByVulnerability(gardenlinuxVersion, cveId, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize)); + var sourcePackageCves = glvdService.getPackagesByVulnerability( + gardenlinuxVersion, cveId, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize) + ); model.addAttribute("sourcePackageCves", sourcePackageCves); model.addAttribute("gardenlinuxVersion", gardenlinuxVersion); model.addAttribute("cveId", cveId); diff --git a/src/main/java/io/gardenlinux/glvd/db/SourcePackageCveRepository.java b/src/main/java/io/gardenlinux/glvd/db/SourcePackageCveRepository.java index 7402392..6d606c1 100644 --- a/src/main/java/io/gardenlinux/glvd/db/SourcePackageCveRepository.java +++ b/src/main/java/io/gardenlinux/glvd/db/SourcePackageCveRepository.java @@ -1,7 +1,6 @@ package io.gardenlinux.glvd.db; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -10,19 +9,39 @@ public interface SourcePackageCveRepository extends JpaRepository { - List findBySourcePackageName(@Param("source_package_name") String source_package_name, Pageable pageable); - List findBySourcePackageNameAndSourcePackageVersion(@Param("source_package_name") String source_package_name, @Param("source_package_version") String source_package_version, Pageable pageable); - List findByCveIdAndGardenlinuxVersion(@Param("cve_id") String cve_id, @Param("gardenlinux_version") String gardenlinux_version, Pageable pageable); + List findBySourcePackageName( + @Param("source_package_name") String source_package_name, + Pageable pageable + ); - List findByGardenlinuxVersion(@Param("gardenlinux_version") String gardenlinux_version, Pageable pageable); + List findBySourcePackageNameAndSourcePackageVersion( + @Param("source_package_name") String source_package_name, + @Param("source_package_version") String source_package_version, + Pageable pageable + ); + + List findByCveIdAndGardenlinuxVersion( + @Param("cve_id") String cve_id, + @Param("gardenlinux_version") String gardenlinux_version, + Pageable pageable + ); + + List findByGardenlinuxVersion( + @Param("gardenlinux_version") String gardenlinux_version, + Pageable pageable + ); // would be nice if we did not need a native query here // is this (the in-array search for packages) possible in any other way with spring data jpa? // fixme: does not support sorting, cf https://github.com/spring-projects/spring-data-jpa/issues/2504#issuecomment-1527743003 // pagination seems to work ok @Query(value = """ - SELECT * FROM sourcepackagecve - WHERE source_package_name = ANY(:source_package_names ::TEXT[]) AND gardenlinux_version = :gardenlinux_version - """, nativeQuery = true) - List findBySourcePackageNameInAndGardenlinuxVersion(@Param("source_package_names") String source_package_names, @Param("gardenlinux_version") String gardenlinux_version, Pageable pageable); + SELECT * FROM sourcepackagecve + WHERE source_package_name = ANY(:source_package_names ::TEXT[]) AND gardenlinux_version = :gardenlinux_version + """, nativeQuery = true) + List findBySourcePackageNameInAndGardenlinuxVersion( + @Param("source_package_names") String source_package_names, + @Param("gardenlinux_version") String gardenlinux_version, + Pageable pageable + ); } diff --git a/src/main/java/io/gardenlinux/glvd/db/SourcePackageRepository.java b/src/main/java/io/gardenlinux/glvd/db/SourcePackageRepository.java index a30a7bb..1dac19d 100644 --- a/src/main/java/io/gardenlinux/glvd/db/SourcePackageRepository.java +++ b/src/main/java/io/gardenlinux/glvd/db/SourcePackageRepository.java @@ -1,12 +1,14 @@ package io.gardenlinux.glvd.db; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.query.Param; import java.util.List; public interface SourcePackageRepository extends JpaRepository { - List findByGardenlinuxVersion(@Param("gardenlinux_version") String gardenlinux_version, Pageable pageable); + List findByGardenlinuxVersion( + @Param("gardenlinux_version") String gardenlinux_version, + Pageable pageable + ); }