diff --git a/src/main/java/com/lpvs/controller/LPVSWebController.java b/src/main/java/com/lpvs/controller/LPVSWebController.java index ec714f80..869499be 100644 --- a/src/main/java/com/lpvs/controller/LPVSWebController.java +++ b/src/main/java/com/lpvs/controller/LPVSWebController.java @@ -289,7 +289,7 @@ public ResponseEntity resultPage( LPVSPullRequest pr = prOpt.get(); List distinctByLicense = - detectedLicenseRepository.findDistinctByPullRequestAndLicense(pr); + detectedLicenseRepository.findDistinctLicenseByPullRequest(pr); List detectedLicenses = new ArrayList<>(); Map licenseCountMap = new HashMap<>(); diff --git a/src/main/java/com/lpvs/repository/LPVSDetectedLicenseRepository.java b/src/main/java/com/lpvs/repository/LPVSDetectedLicenseRepository.java index a9f19084..f13a6d1e 100644 --- a/src/main/java/com/lpvs/repository/LPVSDetectedLicenseRepository.java +++ b/src/main/java/com/lpvs/repository/LPVSDetectedLicenseRepository.java @@ -60,7 +60,7 @@ public interface LPVSDetectedLicenseRepository extends JpaRepository findDistinctByPullRequestAndLicense(@Param("pr") LPVSPullRequest pr); + List findDistinctLicenseByPullRequest(@Param("pr") LPVSPullRequest pr); /** * Find detected licenses associated with a specific pull request where the license is not null. diff --git a/src/main/java/com/lpvs/repository/LPVSLicenseConflictRepository.java b/src/main/java/com/lpvs/repository/LPVSLicenseConflictRepository.java index 1f02b6a2..9f4a7077 100644 --- a/src/main/java/com/lpvs/repository/LPVSLicenseConflictRepository.java +++ b/src/main/java/com/lpvs/repository/LPVSLicenseConflictRepository.java @@ -30,7 +30,7 @@ public interface LPVSLicenseConflictRepository extends JpaRepository * @param spdxId The SPDX identifier of the license. * @return The latest {@link LPVSLicense} entity with the specified SPDX identifier. */ - LPVSLicense findFirstBySpdxIdOrderByIdDesc(@Param("spdxId") String spdxId); + LPVSLicense findFirstBySpdxIdOrderByLicenseIdDesc(@Param("spdxId") String spdxId); /** * Search for a license by alternative license names. @@ -37,7 +37,7 @@ public interface LPVSLicenseRepository extends JpaRepository */ @Query( "SELECT l FROM LPVSLicense l WHERE (CONCAT(',', l.alternativeNames, ',') LIKE CONCAT('%,', :licenseName, ',%')) " - + "ORDER BY l.id DESC LIMIT 1") + + "ORDER BY l.licenseId DESC LIMIT 1") LPVSLicense searchByAlternativeLicenseNames(@Param("licenseName") String licenseName); /** @@ -45,5 +45,6 @@ public interface LPVSLicenseRepository extends JpaRepository * * @return List of SPDX identifiers as Strings. */ + @Query(value = "select l.spdxId from LPVSLicense l") List findAllSpdxId(); } diff --git a/src/main/java/com/lpvs/repository/LPVSPullRequestRepository.java b/src/main/java/com/lpvs/repository/LPVSPullRequestRepository.java index 945f0efa..bcd1d586 100644 --- a/src/main/java/com/lpvs/repository/LPVSPullRequestRepository.java +++ b/src/main/java/com/lpvs/repository/LPVSPullRequestRepository.java @@ -85,6 +85,9 @@ LPVSPullRequest findLatestByPullRequestInfo( * @param pageable The pagination information. * @return Page of {@link LPVSPullRequest} entities with the specified sender or pull request head. */ + @Query( + value = + "select pr from LPVSPullRequest pr where pr.sender = :name or pr.pullRequestHead = :name") Page findBySenderOrPullRequestHead( @Param("name") String name, Pageable pageable); @@ -94,6 +97,9 @@ Page findBySenderOrPullRequestHead( * @param name The name of the sender or pull request head. * @return List of {@link LPVSPullRequest} entities with the specified sender or pull request head. */ + @Query( + value = + "select pr from LPVSPullRequest pr where pr.sender = :name or pr.pullRequestHead = :name") List findBySenderOrPullRequestHead(@Param("name") String name); /** @@ -102,5 +108,8 @@ Page findBySenderOrPullRequestHead( * @param name The name of the sender or pull request head. * @return The count of pull requests with the specified sender or pull request head. */ + @Query( + value = + "select count(*) from LPVSPullRequest pr where pr.sender = :name or pr.pullRequestHead = :name") Long countBySenderOrPullRequestHead(@Param("name") String name); } diff --git a/src/main/java/com/lpvs/service/LPVSGitHubService.java b/src/main/java/com/lpvs/service/LPVSGitHubService.java index 1b8668ee..6ec1a77f 100644 --- a/src/main/java/com/lpvs/service/LPVSGitHubService.java +++ b/src/main/java/com/lpvs/service/LPVSGitHubService.java @@ -309,17 +309,17 @@ public void commentResults( detectedIssue.setPullRequest(lpvsPullRequest); Long l1 = lpvsLicenseRepository - .findFirstBySpdxIdOrderByIdDesc(conflict.l1) + .findFirstBySpdxIdOrderByLicenseIdDesc(conflict.l1) .getLicenseId(); Long l2 = lpvsLicenseRepository - .findFirstBySpdxIdOrderByIdDesc(conflict.l2) + .findFirstBySpdxIdOrderByLicenseIdDesc(conflict.l2) .getLicenseId(); detectedIssue.setLicenseConflict( lpvsLicenseConflictRepository.findLicenseConflict(l1, l2)); if (webhookConfig.getRepositoryLicense() != null) { LPVSLicense repoLicense = - lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc( + lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc( webhookConfig.getRepositoryLicense()); if (repoLicense == null) { repoLicense = diff --git a/src/main/java/com/lpvs/service/LPVSLicenseService.java b/src/main/java/com/lpvs/service/LPVSLicenseService.java index 93fdfd42..74043219 100644 --- a/src/main/java/com/lpvs/service/LPVSLicenseService.java +++ b/src/main/java/com/lpvs/service/LPVSLicenseService.java @@ -376,7 +376,7 @@ public List> findConflicts( if (repositoryLicense != null) { LPVSLicense repoLicense = - lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(repositoryLicense); + lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(repositoryLicense); if (repoLicense == null) { repoLicense = lpvsLicenseRepository.searchByAlternativeLicenseNames(repositoryLicense); diff --git a/src/test/java/com/lpvs/controller/LPVSWebControllerTest.java b/src/test/java/com/lpvs/controller/LPVSWebControllerTest.java index 2e2df94e..281c79d4 100644 --- a/src/test/java/com/lpvs/controller/LPVSWebControllerTest.java +++ b/src/test/java/com/lpvs/controller/LPVSWebControllerTest.java @@ -230,7 +230,7 @@ public void testResultPage() { when(loginCheckService.getMemberFromMemberMap(authentication)).thenReturn(new LPVSMember()); when(lpvsPullRequestRepository.findById(prId)).thenReturn(Optional.of(pullRequest)); - when(detectedLicenseRepository.findDistinctByPullRequestAndLicense(pullRequest)) + when(detectedLicenseRepository.findDistinctLicenseByPullRequest(pullRequest)) .thenReturn(licenses); when(licenseRepository.findAllSpdxId()).thenReturn(List.of("MIT", "Apache-2.0")); when(detectedLicenseRepository.findByPullRequest(pullRequest, pageable)) diff --git a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java index 010f123b..f3f9a720 100644 --- a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java @@ -2255,7 +2255,7 @@ void setUp() { null); conflict_1 = new LPVSLicenseService.Conflict<>(conflict_1_l1, conflict_1_l2); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(anyString())) .thenReturn(lpvs_license_1); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(null); @@ -2310,7 +2310,7 @@ public void testCommentResults__ProhibitedPresentConflictsPresentLicensePresent( throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_1); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_1)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(spdx_id_1)) .thenReturn( new LPVSLicense( 1L, @@ -2369,7 +2369,7 @@ public void testCommentResults__ProhibitedPresentConflictsPresentLicensePresentA throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_2); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_2)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(spdx_id_2)) .thenReturn(null); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(spdx_id_2)) .thenReturn( @@ -2585,7 +2585,7 @@ void setUp() { null); conflict_1 = new LPVSLicenseService.Conflict<>(conflict_1_l1, conflict_1_l2); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(anyString())) .thenReturn(lpvs_license_1); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(null); @@ -2640,7 +2640,7 @@ public void testCommentResults__EmptyPresentConflictsPresentLicensePresent() throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_1); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_1)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(spdx_id_1)) .thenReturn( new LPVSLicense( 1L, @@ -2699,7 +2699,7 @@ public void testCommentResults__EmptyPresentConflictsPresentLicensePresentAlt() throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_2); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_2)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(spdx_id_2)) .thenReturn(null); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(spdx_id_2)) .thenReturn( @@ -2918,7 +2918,7 @@ void setUp() { null); conflict_1 = new LPVSLicenseService.Conflict<>(conflict_1_l1, conflict_1_l2); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(anyString())) .thenReturn(lpvs_license_1); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(null); @@ -2973,7 +2973,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresent( throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_1); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_1)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(spdx_id_1)) .thenReturn( new LPVSLicense( 1L, @@ -3032,7 +3032,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresentA throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_2); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_2)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(spdx_id_2)) .thenReturn(null); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(spdx_id_2)) .thenReturn( @@ -3251,7 +3251,7 @@ void setUp() { null); conflict_1 = new LPVSLicenseService.Conflict<>(conflict_1_l1, conflict_1_l2); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(anyString())) .thenReturn(lpvs_license_1); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(null); @@ -3306,7 +3306,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresent( throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_1); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_1)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(spdx_id_1)) .thenReturn( new LPVSLicense( 1L, @@ -3365,7 +3365,7 @@ public void testCommentResults__RestrictedPresentConflictsPresentLicensePresentA throws Exception { // main test webhookConfig.setRepositoryLicense(spdx_id_2); - when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(spdx_id_2)) + when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(spdx_id_2)) .thenReturn(null); when(mocked_lpvsLicenseRepository.searchByAlternativeLicenseNames(spdx_id_2)) .thenReturn( @@ -4298,7 +4298,9 @@ public void testCommentResults() throws Exception { } }; Mockito.when(repository.getPullRequests(GHIssueState.OPEN)).thenReturn(pullRequestList); - Mockito.when(mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) + Mockito.when( + mocked_lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc( + anyString())) .thenReturn(license); gh_service.commentResults(webhookConfig, fileList, conflictList, lpvsPullRequest); diff --git a/src/test/java/com/lpvs/service/LPVSLicenseServiceTest.java b/src/test/java/com/lpvs/service/LPVSLicenseServiceTest.java index 9e7f50f9..c5855301 100644 --- a/src/test/java/com/lpvs/service/LPVSLicenseServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSLicenseServiceTest.java @@ -155,7 +155,8 @@ public void testFindConflicts() { LPVSLicenseRepository lpvsLicenseRepository = Mockito.mock(LPVSLicenseRepository.class); ReflectionTestUtils.setField( licenseService, "lpvsLicenseRepository", lpvsLicenseRepository); - when(lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())).thenReturn(null); + when(lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(anyString())) + .thenReturn(null); when(lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())).thenReturn(null); Assertions.assertNotNull(licenseService.findConflicts(webhookConfig, fileList)); @@ -442,7 +443,7 @@ void setUp() throws NoSuchFieldException, IllegalAccessException { null, null); - when(lpvsLicenseRepository.findFirstBySpdxIdOrderByIdDesc(anyString())) + when(lpvsLicenseRepository.findFirstBySpdxIdOrderByLicenseIdDesc(anyString())) .thenReturn(null); when(lpvsLicenseRepository.searchByAlternativeLicenseNames(anyString())) .thenReturn(lpvs_license_1);