Skip to content

Commit

Permalink
Improve handling of old Metrics DB entries to avoid showing a metric …
Browse files Browse the repository at this point in the history
…change in UI for first new entry.

Signed-off-by: Ralf King <rkg@mm-software.com>
  • Loading branch information
rkg-mm committed Oct 3, 2024
1 parent 1d81af0 commit 5fc4375
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/dependencytrack/model/ProjectMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ public void setPolicyViolationsOperationalUnaudited(int policyViolationsOperatio
public ProjectCollectionLogic getCollectionLogic() { return collectionLogic; }

public void setCollectionLogic(ProjectCollectionLogic collectionLogic) {
this.collectionLogic = collectionLogic;
// convert old NULL values from DB to NONE
this.collectionLogic = collectionLogic != null ? collectionLogic : ProjectCollectionLogic.NONE;
}

public Boolean isCollectionLogicChanged() { return collectionLogicChanged; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ boolean hasChanged(final ProjectMetrics comparedTo) {
|| comparedTo.getPolicyViolationsOperationalUnaudited() != this.policyViolationsOperationalUnaudited
|| comparedTo.getComponents() != this.components
|| comparedTo.getVulnerableComponents() != this.vulnerableComponents
|| comparedTo.getCollectionLogic() != this.projectCollectionLogic;
|| comparedTo.getCollectionLogic() != this.projectCollectionLogic;
}

boolean hasChanged(final PortfolioMetrics comparedTo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private void updateMetrics(final UUID uuid) throws Exception {
latestMetrics.setLastOccurrence(counters.measuredAt);
} else {
LOGGER.debug("Metrics of project " + uuid + " changed");
final boolean collectionLogicChanged = latestMetrics != null && latestMetrics.getCollectionLogic() != project.getCollectionLogic();
final boolean collectionLogicChanged = latestMetrics != null &&
latestMetrics.getCollectionLogic() != project.getCollectionLogic();
final ProjectMetrics metrics = counters.createProjectMetrics(project, collectionLogicChanged);
pm.makePersistent(metrics);
}
Expand Down

0 comments on commit 5fc4375

Please sign in to comment.