Search in sources :

Example 1 with ProjectRelationship

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)));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) TestUtils.assertTestString(org.eclipse.sw360.datahandler.TestUtils.assertTestString) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple) Test(org.junit.Test)

Example 2 with ProjectRelationship

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);
        }
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple)

Example 3 with ProjectRelationship

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);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)

Example 4 with ProjectRelationship

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);
}
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)

Example 5 with ProjectRelationship

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>");
    }
}
Also used : TException(org.apache.thrift.TException) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) HashMap(java.util.HashMap) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)4 TException (org.apache.thrift.TException)3 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)3 HashMap (java.util.HashMap)2 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)2 ThriftClients (org.eclipse.sw360.datahandler.thrift.ThriftClients)2 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)2 ProjectWithReleaseRelationTuple (org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple)2 User (org.eclipse.sw360.datahandler.thrift.users.User)2 Before (org.junit.Before)2 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)1 ProjectReleaseRelationship (org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship)1 Component (org.eclipse.sw360.datahandler.thrift.components.Component)1 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)1 EccInformation (org.eclipse.sw360.datahandler.thrift.components.EccInformation)1 Test (org.junit.Test)1