use of org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap 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;
}
use of org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap 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);
}
Aggregations