Skip to content

Commit

Permalink
Add new attribute ´affectedComponent´ to Project
Browse files Browse the repository at this point in the history
Adds the new transient attribute ´affectedComponent´ to the ´Project´
class which allows the Frontend to link from the
´Vulnerability - Affected Projects´ tab to the project's dependency
graph with the affected component being highlighted

Signed-off-by: RBickert <[email protected]>
  • Loading branch information
rbt-mm committed Aug 2, 2023
1 parent aec4d9a commit 75f7d0d
Show file tree
Hide file tree
Showing 3 changed files with 14 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

0 comments on commit 75f7d0d

Please sign in to comment.