ProjectDatabaseHandler extends AttachmentAwareDatabaseHandler { SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdToProjects(Project project, User user) throws SW360Exception { Set<String> visitedProjectIds = new HashSet<>(); SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdToProjects = HashMultimap.create(); releaseIdToProjects(project, user, visitedProjectIds, releaseIdToProjects); return releaseIdToProjects; } ProjectDatabaseHandler(Supplier<HttpClient> httpClient, String dbName, String attachmentDbName); @VisibleForTesting  ProjectDatabaseHandler(Supplier<HttpClient> httpClient, String dbName, String attachmentDbName, ProjectModerator moderator, ComponentDatabaseHandler componentDatabaseHandler); List<Project> getMyProjectsSummary(String user); List<Project> getBUProjectsSummary(String organisation); List<Project> getAccessibleProjectsSummary(User user); List<Project> searchByName(String name, User user); Project getProjectById(String id, User user); AddDocumentRequestSummary addProject(Project project, User user); RequestStatus updateProject(Project project, User user); RequestStatus updateProjectFromAdditionsAndDeletions(Project projectAdditions, Project projectDeletions, User user); RequestStatus deleteProject(String id, User user); boolean checkIfInUse(String projectId); List<ProjectLink> getLinkedProjects(Project project, boolean deep, User user); List<ProjectLink> getLinkedProjects(Map<String, ProjectRelationship> relations); Set<Project> searchByReleaseId(String id, User user); Set<Project> searchByReleaseId(Set<String> ids, User user); Set<Project> searchLinkingProjects(String id, User user); Project getProjectForEdit(String id, User user); List<Project> getProjectsById(List<String> id, User user); int getCountByReleaseIds(Set<String> ids); int getCountByProjectId(String id); Set<Project> getAccessibleProjects(User user); Map<String, List<String>> getDuplicateProjects(); List<ProjectVulnerabilityRating> getProjectVulnerabilityRatingByProjectId(String projectId); RequestStatus updateProjectVulnerabilityRating(ProjectVulnerabilityRating link); List<Project> fillClearingStateSummary(List<Project> projects, User user); List<ReleaseClearingStatusData> getReleaseClearingStatuses(String projectId, User user); List<Project> fillClearingStateSummaryIncludingSubprojects(List<Project> projects, User user);  }
@Test public void testReleaseIdToEmptyProjects() throws Exception { SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdToProjects = handler.releaseIdToProjects(new Project().setId("p4"), user1); Set<String> releaseIds = releaseIdToProjects.keySet(); assertTrue("Release IDs size", releaseIds.size() == 0); }
@Test public void testReleaseIdToProjects() throws Exception { Project p1 = handler.getProjectById("P1", user1); p1.setLinkedProjects(ImmutableMap.<String, ProjectRelationship>builder().put("P2", ProjectRelationship.CONTAINED).build()); handler.updateProject(p1, user1); Project p2 = handler.getProjectById("P2", user2); SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdToProjects = handler.releaseIdToProjects(p1, user1); Set<String> releaseIds = releaseIdToProjects.keySet(); assertThat(releaseIds, containsInAnyOrder("r1", "r2","r3","r4","r5","r6")); assertThat(releaseIdToProjects.get("r1"), containsInAnyOrder(createTuple(p1),createTuple(p2))); assertThat(releaseIdToProjects.get("r2"), containsInAnyOrder(createTuple(p1),createTuple(p2))); assertThat(releaseIdToProjects.get("r3"), containsInAnyOrder(createTuple(p1),createTuple(p2))); assertThat(releaseIdToProjects.get("r4"), containsInAnyOrder(createTuple(p1))); assertThat(releaseIdToProjects.get("r5"), containsInAnyOrder(createTuple(p1))); assertThat(releaseIdToProjects.get("r6"), containsInAnyOrder(createTuple(p1))); }