use of org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship in project sw360portal by sw360.
the class ProjectDatabaseHandlerTest method testReleaseIdToProjects.
@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)));
}
use of org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship 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.ProjectRelationship in project sw360portal by sw360.
the class ProjectDatabaseHandler method createProjectLink.
private Optional<ProjectLink> createProjectLink(String id, ProjectRelationship relationship, String parentNodeId, Deque<String> visitedIds, Map<String, Project> projectMap, Map<String, Release> releaseMap, int maxDepth) {
ProjectLink projectLink = null;
if (!visitedIds.contains(id) && (maxDepth < 0 || visitedIds.size() < maxDepth)) {
visitedIds.push(id);
Project project = projectMap.get(id);
if (project != null) {
projectLink = new ProjectLink(id, project.name);
if (project.isSetReleaseIdToUsage() && (maxDepth < 0 || visitedIds.size() < maxDepth)) {
// ProjectLink on the last level does not get children added
List<ReleaseLink> linkedReleases = componentDatabaseHandler.getLinkedReleases(project, releaseMap, visitedIds);
fillMainlineStates(linkedReleases, project.getReleaseIdToUsage());
projectLink.setLinkedReleases(nullToEmptyList(linkedReleases));
}
projectLink.setNodeId(generateNodeId(id)).setParentNodeId(parentNodeId).setRelation(relationship).setVersion(project.getVersion()).setState(project.getState()).setProjectType(project.getProjectType()).setClearingState(project.getClearingState()).setTreeLevel(visitedIds.size() - 1);
if (project.isSetLinkedProjects()) {
List<ProjectLink> subprojectLinks = iterateProjectRelationShips(project.getLinkedProjects(), projectLink.getNodeId(), visitedIds, projectMap, releaseMap, maxDepth);
projectLink.setSubprojects(subprojectLinks);
}
} else {
log.error("Broken ProjectLink in project with id: " + parentNodeId + ". Linked project with id " + id + " was not in the project cache");
}
visitedIds.pop();
}
return Optional.ofNullable(projectLink);
}
use of org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship in project sw360portal by sw360.
the class ProjectPortlet method serveReleasesFromLinkedProjects.
private void serveReleasesFromLinkedProjects(ResourceRequest request, ResourceResponse response, String projectId) throws IOException, PortletException {
List<Release> searchResult;
Set<String> releaseIdsFromLinkedProjects = new HashSet<>();
User user = UserCacheHolder.getUserFromRequest(request);
try {
ComponentService.Iface componentClient = thriftClients.makeComponentClient();
ProjectService.Iface projectClient = thriftClients.makeProjectClient();
Project project = projectClient.getProjectById(projectId, user);
Map<String, ProjectRelationship> linkedProjects = CommonUtils.nullToEmptyMap(project.getLinkedProjects());
for (String linkedProjectId : linkedProjects.keySet()) {
Project linkedProject = projectClient.getProjectById(linkedProjectId, user);
if (linkedProject != null) {
Map<String, ProjectReleaseRelationship> releaseIdToUsage = CommonUtils.nullToEmptyMap(linkedProject.getReleaseIdToUsage());
releaseIdsFromLinkedProjects.addAll(releaseIdToUsage.keySet());
}
}
if (releaseIdsFromLinkedProjects.size() > 0) {
searchResult = componentClient.getReleasesById(releaseIdsFromLinkedProjects, user);
} else {
searchResult = Collections.emptyList();
}
} catch (TException e) {
log.error("Error searching projects", e);
searchResult = Collections.emptyList();
}
request.setAttribute(PortalConstants.RELEASE_SEARCH, searchResult);
include("/html/utils/ajax/searchReleasesAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
use of org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship in project sw360portal by sw360.
the class DisplayProjectChanges method renderProjectLinkListCompare.
private void renderProjectLinkListCompare(StringBuilder display, Map<String, ProjectRelationship> oldProjectRelationshipMap, Map<String, ProjectRelationship> deleteProjectRelationshipMap, Map<String, ProjectRelationship> updateProjectRelationshipMap, Set<String> projectIds, User user) {
if (projectIds.isEmpty())
return;
StringBuilder candidate = new StringBuilder();
try {
ProjectService.Iface client = new ThriftClients().makeProjectClient();
Map<String, ProjectRelationship> changeMap = new HashMap<>();
for (String projectId : projectIds) {
ProjectRelationship updateProjectRelationship = updateProjectRelationshipMap.get(projectId);
ProjectRelationship oldProjectRelationship = oldProjectRelationshipMap.get(projectId);
if (!updateProjectRelationship.equals(oldProjectRelationship)) {
changeMap.put(projectId, oldProjectRelationshipMap.get(projectId));
}
}
// ! This code doubling is done to reduce the database queries. I.e. one big query instead of multiple small ones
for (ProjectLink projectLink : client.getLinkedProjects(changeMap, user)) {
ProjectRelationship updateProjectRelationship = updateProjectRelationshipMap.get(projectLink.getId());
ProjectRelationship deleteProjectRelationship = deleteProjectRelationshipMap.get(projectLink.getId());
ProjectRelationship oldProjectRelationship = oldProjectRelationshipMap.get(projectLink.getId());
candidate.append(String.format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", projectLink.getName(), oldProjectRelationship, deleteProjectRelationship, updateProjectRelationship));
}
} catch (TException ignored) {
}
String tableContent = candidate.toString();
if (!tableContent.isEmpty()) {
display.append(String.format("<table class=\"%s\" id=\"%sUpdated\" >", tableClasses, idPrefix));
display.append("<thead><tr><th colspan=\"4\">Updated Project Links</th></tr>" + "<tr><th>Project Name</th>" + "<th>Current Project Relationship</th>" + "<th>Deleted Project Relationship</th>" + "<th>Suggested Project Relationship</th></tr>" + "</thead><tbody>");
display.append(tableContent);
display.append("</tbody></table>");
}
}
Aggregations