Search in sources :

Example 1 with CommonUtils.nullToEmptyMap

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;
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) SW360Assert.fail(org.eclipse.sw360.datahandler.common.SW360Assert.fail) MailConstants(org.eclipse.sw360.mail.MailConstants) ProjectVulnerabilityRating(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ReleaseClearingStateSummaryComputer(org.eclipse.sw360.datahandler.businessrules.ReleaseClearingStateSummaryComputer) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) Logger(org.apache.log4j.Logger) AttachmentConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentConnector) org.eclipse.sw360.datahandler.thrift(org.eclipse.sw360.datahandler.thrift) ProjectModerator(org.eclipse.sw360.datahandler.entitlement.ProjectModerator) HttpClient(org.ektorp.http.HttpClient) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) MailUtil(org.eclipse.sw360.mail.MailUtil) com.google.common.collect(com.google.common.collect) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) org.eclipse.sw360.datahandler.common(org.eclipse.sw360.datahandler.common) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) PermissionUtils.makePermission(org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission) MalformedURLException(java.net.MalformedURLException) SummaryType(org.eclipse.sw360.components.summary.SummaryType) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple) VisibleForTesting(com.google.common.annotations.VisibleForTesting) org.eclipse.sw360.datahandler.thrift.components(org.eclipse.sw360.datahandler.thrift.components) SW360Assert.assertNotNull(org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull) Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 2 with CommonUtils.nullToEmptyMap

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);
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 com.google.common.collect (com.google.common.collect)1 MalformedURLException (java.net.MalformedURLException)1 Instant (java.time.Instant)1 java.util (java.util)1 TimeUnit (java.util.concurrent.TimeUnit)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.log4j.Logger)1 TException (org.apache.thrift.TException)1 SummaryType (org.eclipse.sw360.components.summary.SummaryType)1 ReleaseClearingStateSummaryComputer (org.eclipse.sw360.datahandler.businessrules.ReleaseClearingStateSummaryComputer)1 org.eclipse.sw360.datahandler.common (org.eclipse.sw360.datahandler.common)1 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)1 SW360Assert.assertNotNull (org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull)1 SW360Assert.fail (org.eclipse.sw360.datahandler.common.SW360Assert.fail)1 SW360Utils (org.eclipse.sw360.datahandler.common.SW360Utils)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1