use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectDatabaseHandlerTest method testDuplicateProjectIsFound.
@Ignore("One is no longer able to create duplicate projects in the db")
public void testDuplicateProjectIsFound() throws Exception {
String originalProjectId = "P1";
final Project tmp = handler.getProjectById(originalProjectId, user1);
tmp.unsetId();
tmp.unsetRevision();
String newProjectId = handler.addProject(tmp, user1).getId();
final Map<String, List<String>> duplicateProjects = handler.getDuplicateProjects();
assertThat(duplicateProjects.size(), is(1));
assertThat(duplicateProjects.get(printName(tmp)), containsInAnyOrder(newProjectId, originalProjectId));
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectDatabaseHandlerTest method setUp.
@Before
public void setUp() throws Exception {
assertTestString(dbName);
assertTestString(attachmentsDbName);
vendors = new ArrayList<>();
vendors.add(new Vendor().setId("V1").setShortname("vendor").setFullname("vendor").setUrl("http://vendor.example.com"));
releases = new ArrayList<>();
Release release1a = new Release().setId("R1A").setComponentId("C1").setName("component1").setVersion("releaseA").setVendorId("V1");
releases.add(release1a);
Release release1b = new Release().setId("R1B").setComponentId("C1").setName("component1").setVersion("releaseB").setVendorId("V1");
releases.add(release1b);
Release release2a = new Release().setId("R2A").setComponentId("C2").setName("component2").setVersion("releaseA").setVendorId("V1");
releases.add(release2a);
Release release2b = new Release().setId("R2B").setComponentId("C2").setName("component2").setVersion("releaseB").setVendorId("V1");
releases.add(release2b);
components = new ArrayList<>();
Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setComponentType(ComponentType.OSS);
components.add(component1);
Component component2 = new Component().setId("C2").setName("component2").setDescription("d2").setComponentType(ComponentType.COTS);
components.add(component2);
projects = new ArrayList<>();
Project project1 = new Project().setId("P1").setName("project1").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
projects.add(project1);
Project project2 = new Project().setId("P2").setName("project2").setLinkedProjects(ImmutableMap.of("P3", ProjectRelationship.REFERRED, "P4", ProjectRelationship.CONTAINED)).setReleaseIdToUsage(ImmutableMap.of("R1A", newDefaultProjectReleaseRelationship(), "R1B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
projects.add(project2);
Project project3 = new Project().setId("P3").setName("project3").setLinkedProjects(ImmutableMap.of("P2", ProjectRelationship.UNKNOWN)).setReleaseIdToUsage(ImmutableMap.of("R2A", newDefaultProjectReleaseRelationship(), "R2B", newDefaultProjectReleaseRelationship())).setVisbility(Visibility.EVERYONE);
projects.add(project3);
Project project4 = new Project().setId("P4").setName("project4").setLinkedProjects(ImmutableMap.of("P1", ProjectRelationship.UNKNOWN)).setVisbility(Visibility.EVERYONE);
projects.add(project4);
Project project5 = new Project().setId("P5").setName("project5").setLinkedProjects(ImmutableMap.of("P6", ProjectRelationship.CONTAINED, "P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
projects.add(project5);
Project project6 = new Project().setId("P6").setName("project6").setLinkedProjects(ImmutableMap.of("P7", ProjectRelationship.CONTAINED)).setVisbility(Visibility.EVERYONE);
projects.add(project6);
Project project7 = new Project().setId("P7").setName("project7").setVisbility(Visibility.EVERYONE);
projects.add(project7);
// Create the database
TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
for (Vendor vendor : vendors) {
databaseConnector.add(vendor);
}
for (Release release : releases) {
databaseConnector.add(release);
}
for (Component component : components) {
databaseConnector.add(component);
}
for (Project project : projects) {
databaseConnector.add(project);
}
ComponentDatabaseHandler componentHandler = new ComponentDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName);
handler = new ProjectDatabaseHandler(DatabaseSettings.getConfiguredHttpClient(), dbName, attachmentsDbName, moderator, componentHandler);
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectDatabaseHandler method releaseIdToProjects.
private void releaseIdToProjects(Project project, User user, Set<String> visitedProjectIds, Multimap<String, ProjectWithReleaseRelationTuple> releaseIdToProjects) throws SW360Exception {
if (nothingTodo(project, visitedProjectIds))
return;
nullToEmptyMap(project.getReleaseIdToUsage()).forEach((releaseId, relation) -> {
releaseIdToProjects.put(releaseId, new ProjectWithReleaseRelationTuple(project, relation));
});
Map<String, ProjectRelationship> linkedProjects = project.getLinkedProjects();
if (linkedProjects != null) {
for (String projectId : linkedProjects.keySet()) {
if (visitedProjectIds.contains(projectId))
continue;
Project linkedProject = getProjectById(projectId, user);
releaseIdToProjects(linkedProject, user, visitedProjectIds, releaseIdToProjects);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectDatabaseHandler method getReleaseIdsOfProjectTree.
private Set<String> getReleaseIdsOfProjectTree(Project project, Set<String> visitedProjectIds, Map<String, Project> allProjectsIdMap, User user, List<RequestedAction> permissionsFilter) {
// no need to visit a project twice
if (visitedProjectIds.contains(project.getId())) {
return Collections.emptySet();
}
// we are now checking this project so no need for further examination in
// recursion
visitedProjectIds.add(project.getId());
// container to aggregate results
Set<String> releaseIds = Sets.newHashSet();
// "DUPLICATE" and add the result to this result
if (project.isSetLinkedProjects()) {
project.getLinkedProjects().entrySet().stream().forEach(e -> {
if (!ProjectRelationship.REFERRED.equals(e.getValue()) && !ProjectRelationship.DUPLICATE.equals(e.getValue())) {
Project childProject = allProjectsIdMap.get(e.getKey());
if (childProject != null) {
// so do it now
if (permissionsFilter == null || permissionsFilter.isEmpty() || makePermission(childProject, user).areActionsAllowed(permissionsFilter)) {
// recursion inside :-)
releaseIds.addAll(getReleaseIdsOfProjectTree(childProject, visitedProjectIds, allProjectsIdMap, user, permissionsFilter));
}
}
}
});
}
// add own releases to result if they are not just "REFERRED"
if (project.isSetReleaseIdToUsage()) {
project.getReleaseIdToUsage().entrySet().stream().forEach(e -> {
if (!ReleaseRelationship.REFERRED.equals(e.getValue().getReleaseRelation())) {
releaseIds.add(e.getKey());
}
});
}
return releaseIds;
}
use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.
the class ProjectDatabaseHandler method fillClearingStateSummary.
public List<Project> fillClearingStateSummary(List<Project> projects, User user) {
Function<Project, Set<String>> extractReleaseIds = project -> CommonUtils.nullToEmptyMap(project.getReleaseIdToUsage()).keySet();
Set<String> allReleaseIds = projects.stream().map(extractReleaseIds).reduce(Sets.newHashSet(), Sets::union);
if (!allReleaseIds.isEmpty()) {
Map<String, Release> releasesById = ThriftUtils.getIdMap(componentDatabaseHandler.getReleasesForClearingStateSummary(allReleaseIds));
for (Project project : projects) {
final Set<String> releaseIds = extractReleaseIds.apply(project);
List<Release> releases = releaseIds.stream().map(releasesById::get).collect(Collectors.toList());
final ReleaseClearingStateSummary releaseClearingStateSummary = ReleaseClearingStateSummaryComputer.computeReleaseClearingStateSummary(releases, project.getClearingTeam());
project.setReleaseClearingStateSummary(releaseClearingStateSummary);
}
}
return projects;
}
Aggregations