Skip to content

Commit

Permalink
Reformat for shorter line length
Browse files Browse the repository at this point in the history
  • Loading branch information
fwilhe committed Sep 16, 2024
1 parent 162cccf commit 0918a08
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 28 deletions.
30 changes: 23 additions & 7 deletions src/main/java/io/gardenlinux/glvd/GlvdController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ ResponseEntity<List<SourcePackageCve>> 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}")
Expand All @@ -40,7 +42,9 @@ ResponseEntity<List<SourcePackageCve>> 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);
}

Expand All @@ -54,7 +58,9 @@ ResponseEntity<List<SourcePackageCve>> 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);
}

Expand All @@ -66,7 +72,9 @@ ResponseEntity<List<SourcePackageCve>> 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}")
Expand All @@ -78,7 +86,11 @@ ResponseEntity<List<SourcePackageCve>> 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}")
Expand All @@ -89,7 +101,9 @@ ResponseEntity<List<SourcePackage>> 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}")
Expand All @@ -101,7 +115,9 @@ ResponseEntity<List<SourcePackageCve>> 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))
);
}

}
28 changes: 22 additions & 6 deletions src/main/java/io/gardenlinux/glvd/GlvdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,43 @@ private Pageable determinePageAndSortFeatures2(SortAndPageOptions sortAndPageOpt
}

public List<SourcePackageCve> 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<SourcePackageCve> getCveForPackages(String gardenlinuxVersion, String packages, SortAndPageOptions sortAndPageOptions) {
return sourcePackageCveRepository.findBySourcePackageNameInAndGardenlinuxVersion("{" + packages + "}", gardenlinuxVersion, determinePageAndSortFeatures2(sortAndPageOptions));
return sourcePackageCveRepository.findBySourcePackageNameInAndGardenlinuxVersion(
wrap(packages), gardenlinuxVersion, determinePageAndSortFeatures2(sortAndPageOptions)
);
}

public List<SourcePackage> getPackagesForDistro(String gardenlinuxVersion, SortAndPageOptions sortAndPageOptions) {
return sourcePackageRepository.findByGardenlinuxVersion(gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions));
return sourcePackageRepository.findByGardenlinuxVersion(
gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions)
);
}

public List<SourcePackageCve> getPackageWithVulnerabilities(String sourcePackage, SortAndPageOptions sortAndPageOptions) {
return sourcePackageCveRepository.findBySourcePackageName(sourcePackage, determinePageAndSortFeatures(sortAndPageOptions));
return sourcePackageCveRepository.findBySourcePackageName(
sourcePackage, determinePageAndSortFeatures(sortAndPageOptions)
);
}

public List<SourcePackageCve> getPackageWithVulnerabilitiesByVersion(String sourcePackage, String sourcePackageVersion, SortAndPageOptions sortAndPageOptions) {
return sourcePackageCveRepository.findBySourcePackageNameAndSourcePackageVersion(sourcePackage, sourcePackageVersion, determinePageAndSortFeatures(sortAndPageOptions));
return sourcePackageCveRepository.findBySourcePackageNameAndSourcePackageVersion(
sourcePackage, sourcePackageVersion, determinePageAndSortFeatures(sortAndPageOptions)
);
}

public List<SourcePackageCve> getPackagesByVulnerability(String gardenlinuxVersion, String cveId, SortAndPageOptions sortAndPageOptions) {
return sourcePackageCveRepository.findByCveIdAndGardenlinuxVersion(cveId, gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions));
return sourcePackageCveRepository.findByCveIdAndGardenlinuxVersion(
cveId, gardenlinuxVersion, determinePageAndSortFeatures(sortAndPageOptions)
);
}

}
16 changes: 12 additions & 4 deletions src/main/java/io/gardenlinux/glvd/UiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,19 +9,39 @@

public interface SourcePackageCveRepository extends JpaRepository<SourcePackageCve, String> {

List<SourcePackageCve> findBySourcePackageName(@Param("source_package_name") String source_package_name, Pageable pageable);
List<SourcePackageCve> findBySourcePackageNameAndSourcePackageVersion(@Param("source_package_name") String source_package_name, @Param("source_package_version") String source_package_version, Pageable pageable);
List<SourcePackageCve> findByCveIdAndGardenlinuxVersion(@Param("cve_id") String cve_id, @Param("gardenlinux_version") String gardenlinux_version, Pageable pageable);
List<SourcePackageCve> findBySourcePackageName(
@Param("source_package_name") String source_package_name,
Pageable pageable
);

List<SourcePackageCve> findByGardenlinuxVersion(@Param("gardenlinux_version") String gardenlinux_version, Pageable pageable);
List<SourcePackageCve> findBySourcePackageNameAndSourcePackageVersion(
@Param("source_package_name") String source_package_name,
@Param("source_package_version") String source_package_version,
Pageable pageable
);

List<SourcePackageCve> findByCveIdAndGardenlinuxVersion(
@Param("cve_id") String cve_id,
@Param("gardenlinux_version") String gardenlinux_version,
Pageable pageable
);

List<SourcePackageCve> 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<SourcePackageCve> 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<SourcePackageCve> findBySourcePackageNameInAndGardenlinuxVersion(
@Param("source_package_names") String source_package_names,
@Param("gardenlinux_version") String gardenlinux_version,
Pageable pageable
);
}
Original file line number Diff line number Diff line change
@@ -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<SourcePackage, String> {
List<SourcePackage> findByGardenlinuxVersion(@Param("gardenlinux_version") String gardenlinux_version, Pageable pageable);
List<SourcePackage> findByGardenlinuxVersion(
@Param("gardenlinux_version") String gardenlinux_version,
Pageable pageable
);
}

0 comments on commit 0918a08

Please sign in to comment.