Skip to content

Commit

Permalink
Merge pull request #26 from rbt-mm/rbt-open-dependency-graph-from-aff…
Browse files Browse the repository at this point in the history
…ected-projects

Add "Show in Dependency-Graph" Button in "Affected Projects" List
  • Loading branch information
rbt-mm authored Aug 8, 2023
2 parents aec4d9a + 0fae5e8 commit c301d0d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/dependencytrack/model/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ public enum FetchGroup {
@JsonIgnore
private transient List<Component> dependencyGraph;

private transient UUID affectedComponent;

public long getId() {
return id;
}
Expand Down Expand Up @@ -492,6 +494,14 @@ public void setDependencyGraph(List<Component> dependencyGraph) {
this.dependencyGraph = dependencyGraph;
}

public UUID getAffectedComponent() {
return affectedComponent;
}

public void setAffectedComponent(UUID affectedComponent) {
this.affectedComponent = affectedComponent;
}

@Override
public String toString() {
if (getPurl() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,9 @@ public List<Project> getProjects(Vulnerability vulnerability) {
affected = false;
}
if (affected) {
projects.add(component.getProject());
Project project = component.getProject();
project.setAffectedComponent(component.getUuid());
projects.add(project);
}
}
// Force removal of duplicates by taking the List and populating a Set and back again.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public Response getAffectedProject(@PathParam("source") String source,
try (QueryManager qm = new QueryManager(getAlpineRequest())) {
final Vulnerability vulnerability = qm.getVulnerabilityByVulnId(source, vuln);
if (vulnerability != null) {
final List<Project> projects = qm.detach(qm.getProjects(vulnerability));
final List<Project> projects = qm.getProjects(vulnerability);
final long totalCount = projects.size();
return Response.ok(projects).header(TOTAL_COUNT_HEADER, totalCount).build();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public void getAffectedProjectTest() throws Exception {
Assert.assertNotNull(json);
Assert.assertEquals("Project 1", json.getJsonObject(0).getString("name"));
Assert.assertEquals(sampleData.p1.getUuid().toString(), json.getJsonObject(0).getString("uuid"));
Assert.assertEquals(sampleData.c1.getUuid().toString(), json.getJsonObject(0).getString("affectedComponent"));
}

@Test
Expand Down

0 comments on commit c301d0d

Please sign in to comment.